Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -8,21 +8,15 @@ from threading import Thread
|
|
8 |
|
9 |
MODEL_LIST = ["nawhgnuj/DonaldTrump-Llama-3.1-8B-Chat"]
|
10 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
11 |
-
MODEL = os.environ.get("MODEL_ID")
|
12 |
|
13 |
-
TITLE = "<h1 style='color: #
|
14 |
|
15 |
-
|
16 |
-
<div style='text-align: center;'>
|
17 |
-
<img src='https://upload.wikimedia.org/wikipedia/commons/5/56/Donald_Trump_official_portrait.jpg' style='width: 200px; border-radius: 50%;'>
|
18 |
-
<p style='color: #E53935; font-weight: bold;'>Hi! I'm Donald Trump!</p>
|
19 |
-
<p>Let's Make America Great Again! Ask me anything.</p>
|
20 |
-
</div>
|
21 |
-
"""
|
22 |
|
23 |
CSS = """
|
24 |
.chatbot {
|
25 |
-
background-color:
|
26 |
}
|
27 |
.duplicate-button {
|
28 |
margin: auto !important;
|
@@ -32,7 +26,17 @@ CSS = """
|
|
32 |
}
|
33 |
h3 {
|
34 |
text-align: center;
|
35 |
-
color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
}
|
37 |
"""
|
38 |
|
@@ -98,20 +102,52 @@ def stream_chat(
|
|
98 |
buffer += new_text
|
99 |
yield buffer
|
100 |
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
with gr.Blocks(css=CSS, theme=gr.themes.Default()) as demo:
|
104 |
gr.HTML(TITLE)
|
105 |
-
gr.
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
examples=[
|
110 |
-
["What do you think about the economy?"],
|
111 |
-
["How would you handle foreign policy?"],
|
112 |
["What's your stance on immigration?"],
|
|
|
|
|
113 |
],
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
)
|
116 |
|
117 |
if __name__ == "__main__":
|
|
|
8 |
|
9 |
MODEL_LIST = ["nawhgnuj/DonaldTrump-Llama-3.1-8B-Chat"]
|
10 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
11 |
+
MODEL = os.environ.get("MODEL_ID", "nawhgnuj/DonaldTrump-Llama-3.1-8B-Chat")
|
12 |
|
13 |
+
TITLE = "<h1 style='color: #B71C1C; text-align: center;'>Donald Trump Chatbot</h1>"
|
14 |
|
15 |
+
TRUMP_AVATAR = "https://upload.wikimedia.org/wikipedia/commons/5/56/Donald_Trump_official_portrait.jpg"
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
CSS = """
|
18 |
.chatbot {
|
19 |
+
background-color: white;
|
20 |
}
|
21 |
.duplicate-button {
|
22 |
margin: auto !important;
|
|
|
26 |
}
|
27 |
h3 {
|
28 |
text-align: center;
|
29 |
+
color: #B71C1C;
|
30 |
+
}
|
31 |
+
.contain {object-fit: contain}
|
32 |
+
.avatar {width: 40px; height: 40px; border-radius: 50%; object-fit: cover;}
|
33 |
+
.user-message {
|
34 |
+
background-color: white !important;
|
35 |
+
color: black !important;
|
36 |
+
}
|
37 |
+
.bot-message {
|
38 |
+
background-color: #B71C1C !important;
|
39 |
+
color: white !important;
|
40 |
}
|
41 |
"""
|
42 |
|
|
|
102 |
buffer += new_text
|
103 |
yield buffer
|
104 |
|
105 |
+
def add_text(history, text):
|
106 |
+
history = history + [(text, None)]
|
107 |
+
return history, ""
|
108 |
+
|
109 |
+
def bot(history):
|
110 |
+
user_message = history[-1][0]
|
111 |
+
bot_response = stream_chat(user_message, history[:-1])
|
112 |
+
history[-1][1] = ""
|
113 |
+
for character in bot_response:
|
114 |
+
history[-1][1] += character
|
115 |
+
yield history
|
116 |
|
117 |
with gr.Blocks(css=CSS, theme=gr.themes.Default()) as demo:
|
118 |
gr.HTML(TITLE)
|
119 |
+
chatbot = gr.Chatbot(
|
120 |
+
[],
|
121 |
+
elem_id="chatbot",
|
122 |
+
avatar_images=(None, TRUMP_AVATAR),
|
123 |
+
height=600,
|
124 |
+
bubble_full_width=False,
|
125 |
+
show_label=False,
|
126 |
+
)
|
127 |
+
msg = gr.Textbox(
|
128 |
+
placeholder="Ask Donald Trump a question",
|
129 |
+
container=False,
|
130 |
+
scale=7
|
131 |
+
)
|
132 |
+
with gr.Row():
|
133 |
+
submit = gr.Button("Submit", scale=1, variant="primary")
|
134 |
+
clear = gr.Button("Clear", scale=1)
|
135 |
+
|
136 |
+
gr.Examples(
|
137 |
examples=[
|
|
|
|
|
138 |
["What's your stance on immigration?"],
|
139 |
+
["How would you describe your economic policies?"],
|
140 |
+
["What are your thoughts on the media?"],
|
141 |
],
|
142 |
+
inputs=msg,
|
143 |
+
)
|
144 |
+
|
145 |
+
submit.click(add_text, [chatbot, msg], [chatbot, msg], queue=False).then(
|
146 |
+
bot, chatbot, chatbot
|
147 |
+
)
|
148 |
+
clear.click(lambda: [], outputs=[chatbot], queue=False)
|
149 |
+
msg.submit(add_text, [chatbot, msg], [chatbot, msg], queue=False).then(
|
150 |
+
bot, chatbot, chatbot
|
151 |
)
|
152 |
|
153 |
if __name__ == "__main__":
|