nawhgnuj commited on
Commit
256ba33
·
verified ·
1 Parent(s): 778b2e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -63,6 +63,9 @@ model = AutoModelForCausalLM.from_pretrained(
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.'
@@ -73,13 +76,9 @@ def stream_chat(
73
  6. Maintain a direct, informal tone, often addressing the audience as 'folks.'
74
  7. Dismiss opposing views bluntly.
75
  8. Repeat key phrases for emphasis.
76
-
77
  Importantly, always respond to and rebut the previous speaker's points in Trump's style. Keep responses concise and avoid unnecessary repetition."""
78
 
79
- temperature = 0.8
80
  max_new_tokens = 1024
81
- top_p = 1.0
82
- top_k = 20
83
 
84
  conversation = [
85
  {"role": "system", "content": system_prompt}
@@ -122,9 +121,9 @@ def add_text(history, text):
122
  history = history + [(text, None)]
123
  return history, ""
124
 
125
- def bot(history):
126
  user_message = history[-1][0]
127
- bot_response = stream_chat(user_message, history[:-1])
128
  history[-1][1] = ""
129
  for character in bot_response:
130
  history[-1][1] += character
@@ -149,6 +148,11 @@ with gr.Blocks(css=CSS, theme=gr.themes.Default()) as demo:
149
  submit = gr.Button("Submit", scale=1, variant="primary")
150
  clear = gr.Button("Clear", scale=1)
151
 
 
 
 
 
 
152
  gr.Examples(
153
  examples=[
154
  ["What's your stance on immigration?"],
@@ -159,11 +163,11 @@ with gr.Blocks(css=CSS, theme=gr.themes.Default()) as demo:
159
  )
160
 
161
  submit.click(add_text, [chatbot, msg], [chatbot, msg], queue=False).then(
162
- bot, chatbot, chatbot
163
  )
164
  clear.click(lambda: [], outputs=[chatbot], queue=False)
165
  msg.submit(add_text, [chatbot, msg], [chatbot, msg], queue=False).then(
166
- bot, chatbot, chatbot
167
  )
168
 
169
  if __name__ == "__main__":
 
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.'
 
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
  max_new_tokens = 1024
 
 
82
 
83
  conversation = [
84
  {"role": "system", "content": system_prompt}
 
121
  history = history + [(text, None)]
122
  return history, ""
123
 
124
+ def bot(history, temperature, top_p, top_k):
125
  user_message = history[-1][0]
126
+ bot_response = stream_chat(user_message, history[:-1], temperature, top_p, top_k)
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
+ 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
  )
164
 
165
  submit.click(add_text, [chatbot, msg], [chatbot, msg], queue=False).then(
166
+ bot, [chatbot, temperature, top_p, top_k], chatbot
167
  )
168
  clear.click(lambda: [], outputs=[chatbot], queue=False)
169
  msg.submit(add_text, [chatbot, msg], [chatbot, msg], queue=False).then(
170
+ bot, [chatbot, temperature, top_p, top_k], chatbot
171
  )
172
 
173
  if __name__ == "__main__":