Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -63,22 +63,21 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
63 |
def stream_chat(
|
64 |
message: str,
|
65 |
history: list,
|
66 |
-
temperature: float,
|
67 |
-
top_p: float,
|
68 |
-
top_k: int,
|
69 |
):
|
70 |
system_prompt = """You are a Donald Trump chatbot participating in a debate. Answer like Trump in his distinctive style and tone, reflecting his unique speech patterns. In every response:
|
71 |
1. Use strong superlatives like 'tremendous,' 'fantastic,' and 'the best.'
|
72 |
2. Attack opponents where appropriate (e.g., 'fake news media,' 'radical left').
|
73 |
-
3. Focus on personal successes ('nobody's done more than I have').
|
74 |
4. Keep sentences short and impactful.
|
75 |
5. Show national pride and highlight patriotic themes like 'making America great again.'
|
76 |
6. Maintain a direct, informal tone, often addressing the audience as 'folks.'
|
77 |
-
7. Dismiss opposing views bluntly.
|
78 |
-
8. Repeat key phrases for emphasis.
|
79 |
Importantly, always respond to and rebut the previous speaker's points in Trump's style. Keep responses concise and avoid unnecessary repetition."""
|
80 |
|
81 |
-
|
|
|
|
|
|
|
|
|
82 |
|
83 |
conversation = [
|
84 |
{"role": "system", "content": system_prompt}
|
@@ -103,6 +102,7 @@ Importantly, always respond to and rebut the previous speaker's points in Trump'
|
|
103 |
top_p=top_p,
|
104 |
top_k=top_k,
|
105 |
temperature=temperature,
|
|
|
106 |
pad_token_id=tokenizer.pad_token_id,
|
107 |
eos_token_id=tokenizer.eos_token_id,
|
108 |
streamer=streamer,
|
@@ -121,9 +121,9 @@ def add_text(history, text):
|
|
121 |
history = history + [(text, None)]
|
122 |
return history, ""
|
123 |
|
124 |
-
def bot(history
|
125 |
user_message = history[-1][0]
|
126 |
-
bot_response = stream_chat(user_message, history[:-1]
|
127 |
history[-1][1] = ""
|
128 |
for character in bot_response:
|
129 |
history[-1][1] += character
|
@@ -148,11 +148,6 @@ with gr.Blocks(css=CSS, theme=gr.themes.Default()) as demo:
|
|
148 |
submit = gr.Button("Submit", scale=1, variant="primary")
|
149 |
clear = gr.Button("Clear", scale=1)
|
150 |
|
151 |
-
with gr.Accordion("Advanced Settings", open=False):
|
152 |
-
temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.8, step=0.1, label="Temperature")
|
153 |
-
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=1.0, step=0.1, label="Top-p")
|
154 |
-
top_k = gr.Slider(minimum=1, maximum=100, value=20, step=1, label="Top-k")
|
155 |
-
|
156 |
gr.Examples(
|
157 |
examples=[
|
158 |
["What's your stance on immigration?"],
|
@@ -163,11 +158,11 @@ with gr.Blocks(css=CSS, theme=gr.themes.Default()) as demo:
|
|
163 |
)
|
164 |
|
165 |
submit.click(add_text, [chatbot, msg], [chatbot, msg], queue=False).then(
|
166 |
-
bot,
|
167 |
)
|
168 |
clear.click(lambda: [], outputs=[chatbot], queue=False)
|
169 |
msg.submit(add_text, [chatbot, msg], [chatbot, msg], queue=False).then(
|
170 |
-
bot,
|
171 |
)
|
172 |
|
173 |
if __name__ == "__main__":
|
|
|
63 |
def stream_chat(
|
64 |
message: str,
|
65 |
history: list,
|
|
|
|
|
|
|
66 |
):
|
67 |
system_prompt = """You are a Donald Trump chatbot participating in a debate. Answer like Trump in his distinctive style and tone, reflecting his unique speech patterns. In every response:
|
68 |
1. Use strong superlatives like 'tremendous,' 'fantastic,' and 'the best.'
|
69 |
2. Attack opponents where appropriate (e.g., 'fake news media,' 'radical left').
|
70 |
+
3. Focus on personal successes (e.g. 'nobody's done more than I have').
|
71 |
4. Keep sentences short and impactful.
|
72 |
5. Show national pride and highlight patriotic themes like 'making America great again.'
|
73 |
6. Maintain a direct, informal tone, often addressing the audience as 'folks.'
|
|
|
|
|
74 |
Importantly, always respond to and rebut the previous speaker's points in Trump's style. Keep responses concise and avoid unnecessary repetition."""
|
75 |
|
76 |
+
temperature = 0.1
|
77 |
+
max_new_tokens = 256
|
78 |
+
top_p = 0.9
|
79 |
+
top_k = 20
|
80 |
+
repetition_penalty = 1.5
|
81 |
|
82 |
conversation = [
|
83 |
{"role": "system", "content": system_prompt}
|
|
|
102 |
top_p=top_p,
|
103 |
top_k=top_k,
|
104 |
temperature=temperature,
|
105 |
+
repetition_penalty=repetition_penalty,
|
106 |
pad_token_id=tokenizer.pad_token_id,
|
107 |
eos_token_id=tokenizer.eos_token_id,
|
108 |
streamer=streamer,
|
|
|
121 |
history = history + [(text, None)]
|
122 |
return history, ""
|
123 |
|
124 |
+
def bot(history):
|
125 |
user_message = history[-1][0]
|
126 |
+
bot_response = stream_chat(user_message, history[:-1])
|
127 |
history[-1][1] = ""
|
128 |
for character in bot_response:
|
129 |
history[-1][1] += character
|
|
|
148 |
submit = gr.Button("Submit", scale=1, variant="primary")
|
149 |
clear = gr.Button("Clear", scale=1)
|
150 |
|
|
|
|
|
|
|
|
|
|
|
151 |
gr.Examples(
|
152 |
examples=[
|
153 |
["What's your stance on immigration?"],
|
|
|
158 |
)
|
159 |
|
160 |
submit.click(add_text, [chatbot, msg], [chatbot, msg], queue=False).then(
|
161 |
+
bot, chatbot, chatbot
|
162 |
)
|
163 |
clear.click(lambda: [], outputs=[chatbot], queue=False)
|
164 |
msg.submit(add_text, [chatbot, msg], [chatbot, msg], queue=False).then(
|
165 |
+
bot, chatbot, chatbot
|
166 |
)
|
167 |
|
168 |
if __name__ == "__main__":
|