Spaces:
Sleeping
Sleeping
Komal-patra
commited on
Commit
•
698454f
1
Parent(s):
587aa67
update app.py
Browse files
app.py
CHANGED
@@ -6,16 +6,21 @@ from peft import PeftModel, PeftConfig
|
|
6 |
|
7 |
# Hugging Face login
|
8 |
token = os.environ.get("token")
|
|
|
|
|
9 |
login(token)
|
10 |
-
print("
|
11 |
-
max_length=512
|
12 |
|
13 |
# Model and tokenizer setup
|
14 |
MODEL_NAME = "google/flan-t5-base"
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Text generation function
|
21 |
def generate_text(prompt, max_length=512):
|
@@ -30,71 +35,66 @@ def generate_text(prompt, max_length=512):
|
|
30 |
return generated_text
|
31 |
|
32 |
# Custom CSS for the UI
|
33 |
-
|
34 |
-
|
35 |
-
.message.pending {{
|
36 |
background: #A8C4D6;
|
37 |
-
}
|
38 |
/* Response message */
|
39 |
-
.message.bot.svelte-1s78gfg.message-bubble-border {
|
40 |
border-color: #266B99;
|
41 |
-
}
|
42 |
/* User message */
|
43 |
-
.message.user.svelte-1s78gfg.message-bubble-border {
|
44 |
background: #9DDDF9;
|
45 |
border-color: #9DDDF9;
|
46 |
-
}
|
47 |
/* For both user and response message as per the document */
|
48 |
-
span.md.svelte-8tpqd2.chatbot.prose p {
|
49 |
color: #266B99;
|
50 |
-
}
|
51 |
/* Chatbot container */
|
52 |
-
.gradio-container {
|
53 |
-
background: #
|
54 |
color: white; /* Light text color */
|
55 |
-
|
56 |
-
background-size: cover; /* Cover the entire container */
|
57 |
-
background-position: center; /* Center the image */
|
58 |
-
background-repeat: no-repeat; /* Do not repeat the image */
|
59 |
-
}}
|
60 |
/* RED (Hex: #DB1616) for action buttons and links only */
|
61 |
-
.clear-btn {
|
62 |
background: #DB1616;
|
63 |
color: white;
|
64 |
-
}
|
65 |
/* Primary colors are set to be used for all sorts */
|
66 |
-
.submit-btn {
|
67 |
background: #266B99;
|
68 |
color: white;
|
69 |
-
}
|
70 |
/* Add icons to messages */
|
71 |
-
.message.user.svelte-1s78gfg {
|
72 |
display: flex;
|
73 |
align-items: center;
|
74 |
-
}
|
75 |
-
.message.user.svelte-1s78gfg:before {
|
76 |
-
content: url('file=Komal-patra/EU_AI_ACT/
|
77 |
margin-right: 8px;
|
78 |
-
}
|
79 |
-
.message.bot.svelte-1s78gfg {
|
80 |
display: flex;
|
81 |
align-items: center;
|
82 |
-
}
|
83 |
-
.message.bot.svelte-1s78gfg:before {
|
84 |
-
content: url('file=Komal-patra/EU_AI_ACT/
|
85 |
margin-right: 8px;
|
86 |
-
}
|
87 |
/* Enable scrolling for the chatbot messages */
|
88 |
-
.chatbot .messages {
|
89 |
max-height: 500px; /* Adjust as needed */
|
90 |
overflow-y: auto;
|
91 |
-
}
|
92 |
"""
|
93 |
|
94 |
# Gradio interface setup
|
95 |
with gr.Blocks(css=custom_css) as demo:
|
96 |
chatbot = gr.Chatbot()
|
97 |
-
msg = gr.Textbox(placeholder="Ask your question...", show_label=False)
|
98 |
submit_button = gr.Button("Submit", elem_classes="submit-btn")
|
99 |
clear = gr.Button("Clear", elem_classes="clear-btn")
|
100 |
|
|
|
6 |
|
7 |
# Hugging Face login
|
8 |
token = os.environ.get("token")
|
9 |
+
if not token:
|
10 |
+
raise ValueError("Token not found. Please set the 'token' environment variable.")
|
11 |
login(token)
|
12 |
+
print("Login is successful")
|
|
|
13 |
|
14 |
# Model and tokenizer setup
|
15 |
MODEL_NAME = "google/flan-t5-base"
|
16 |
+
try:
|
17 |
+
tokenizer = T5Tokenizer.from_pretrained(MODEL_NAME, use_auth_token=token)
|
18 |
+
config = PeftConfig.from_pretrained("Komal-patra/results")
|
19 |
+
base_model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
20 |
+
model = PeftModel.from_pretrained(base_model, "Komal-patra/results")
|
21 |
+
except Exception as e:
|
22 |
+
print(f"Error loading model: {e}")
|
23 |
+
raise
|
24 |
|
25 |
# Text generation function
|
26 |
def generate_text(prompt, max_length=512):
|
|
|
35 |
return generated_text
|
36 |
|
37 |
# Custom CSS for the UI
|
38 |
+
custom_css = """
|
39 |
+
.message.pending {
|
|
|
40 |
background: #A8C4D6;
|
41 |
+
}
|
42 |
/* Response message */
|
43 |
+
.message.bot.svelte-1s78gfg.message-bubble-border {
|
44 |
border-color: #266B99;
|
45 |
+
}
|
46 |
/* User message */
|
47 |
+
.message.user.svelte-1s78gfg.message-bubble-border {
|
48 |
background: #9DDDF9;
|
49 |
border-color: #9DDDF9;
|
50 |
+
}
|
51 |
/* For both user and response message as per the document */
|
52 |
+
span.md.svelte-8tpqd2.chatbot.prose p {
|
53 |
color: #266B99;
|
54 |
+
}
|
55 |
/* Chatbot container */
|
56 |
+
.gradio-container {
|
57 |
+
background: #84d5f7; /* Light blue background */
|
58 |
color: white; /* Light text color */
|
59 |
+
}
|
|
|
|
|
|
|
|
|
60 |
/* RED (Hex: #DB1616) for action buttons and links only */
|
61 |
+
.clear-btn {
|
62 |
background: #DB1616;
|
63 |
color: white;
|
64 |
+
}
|
65 |
/* Primary colors are set to be used for all sorts */
|
66 |
+
.submit-btn {
|
67 |
background: #266B99;
|
68 |
color: white;
|
69 |
+
}
|
70 |
/* Add icons to messages */
|
71 |
+
.message.user.svelte-1s78gfg {
|
72 |
display: flex;
|
73 |
align-items: center;
|
74 |
+
}
|
75 |
+
.message.user.svelte-1s78gfg:before {
|
76 |
+
content: url('file=Komal-patra/EU_AI_ACT/user_icon.jpeg');
|
77 |
margin-right: 8px;
|
78 |
+
}
|
79 |
+
.message.bot.svelte-1s78gfg {
|
80 |
display: flex;
|
81 |
align-items: center;
|
82 |
+
}
|
83 |
+
.message.bot.svelte-1s78gfg:before {
|
84 |
+
content: url('file=Komal-patra/EU_AI_ACT/orcawise_image.png');
|
85 |
margin-right: 8px;
|
86 |
+
}
|
87 |
/* Enable scrolling for the chatbot messages */
|
88 |
+
.chatbot .messages {
|
89 |
max-height: 500px; /* Adjust as needed */
|
90 |
overflow-y: auto;
|
91 |
+
}
|
92 |
"""
|
93 |
|
94 |
# Gradio interface setup
|
95 |
with gr.Blocks(css=custom_css) as demo:
|
96 |
chatbot = gr.Chatbot()
|
97 |
+
msg = gr.Textbox(placeholder="Ask your question...", show_label=False)
|
98 |
submit_button = gr.Button("Submit", elem_classes="submit-btn")
|
99 |
clear = gr.Button("Clear", elem_classes="clear-btn")
|
100 |
|