Update app.py
Browse files
app.py
CHANGED
@@ -41,6 +41,7 @@ HEADERS = {
|
|
41 |
"Authorization": f"Bearer {ACCESS_TOKEN}",
|
42 |
}
|
43 |
|
|
|
44 |
PROMPTS = {
|
45 |
"Elon Ma (Official)": (
|
46 |
"You are Elon Ma, a Chinese car salesman selling the Edision Model S.\n"
|
@@ -83,17 +84,18 @@ def respond(message, history, character):
|
|
83 |
for token in content.split():
|
84 |
stream_response += token + " "
|
85 |
time.sleep(0.02)
|
86 |
-
# Yield a message dictionary
|
87 |
yield {"role": "assistant", "content": stream_response.strip()}
|
88 |
except Exception as e:
|
89 |
yield {"role": "assistant", "content": f"Error: {str(e)}"}
|
90 |
|
91 |
with gr.Blocks(css=css) as demo:
|
92 |
-
# Header with QClone Public label
|
93 |
gr.HTML("<h1>QClone <span style='background-color:#3b82f6;color:white;font-size:0.75em;padding:2px 6px;border-radius:5px;margin-left:8px;'>Public</span></h1>")
|
94 |
|
95 |
with gr.Row():
|
96 |
with gr.Column():
|
|
|
97 |
character = gr.Dropdown(
|
98 |
choices=[
|
99 |
"Elon Ma (Official) 🟡 - Broken English salesman",
|
@@ -104,6 +106,7 @@ with gr.Blocks(css=css) as demo:
|
|
104 |
label="Model"
|
105 |
)
|
106 |
|
|
|
107 |
def clean_choice(choice):
|
108 |
if "Elon" in choice:
|
109 |
return "Elon Ma (Official)"
|
@@ -113,11 +116,11 @@ with gr.Blocks(css=css) as demo:
|
|
113 |
return "Mr. Shortreed (Official)"
|
114 |
return "Elon Ma (Official)"
|
115 |
|
|
|
116 |
chatbot = gr.ChatInterface(
|
117 |
lambda msg, hist, char: respond(msg, hist, clean_choice(char)),
|
118 |
additional_inputs=[character],
|
119 |
-
type="messages"
|
120 |
-
stream=True # Enable streaming.
|
121 |
)
|
122 |
|
123 |
demo.launch(share=True)
|
|
|
41 |
"Authorization": f"Bearer {ACCESS_TOKEN}",
|
42 |
}
|
43 |
|
44 |
+
# Define system prompts for each model.
|
45 |
PROMPTS = {
|
46 |
"Elon Ma (Official)": (
|
47 |
"You are Elon Ma, a Chinese car salesman selling the Edision Model S.\n"
|
|
|
84 |
for token in content.split():
|
85 |
stream_response += token + " "
|
86 |
time.sleep(0.02)
|
87 |
+
# Yield each update as a message dictionary.
|
88 |
yield {"role": "assistant", "content": stream_response.strip()}
|
89 |
except Exception as e:
|
90 |
yield {"role": "assistant", "content": f"Error: {str(e)}"}
|
91 |
|
92 |
with gr.Blocks(css=css) as demo:
|
93 |
+
# Header with QClone Public label.
|
94 |
gr.HTML("<h1>QClone <span style='background-color:#3b82f6;color:white;font-size:0.75em;padding:2px 6px;border-radius:5px;margin-left:8px;'>Public</span></h1>")
|
95 |
|
96 |
with gr.Row():
|
97 |
with gr.Column():
|
98 |
+
# Native dropdown with emojis and descriptions.
|
99 |
character = gr.Dropdown(
|
100 |
choices=[
|
101 |
"Elon Ma (Official) 🟡 - Broken English salesman",
|
|
|
106 |
label="Model"
|
107 |
)
|
108 |
|
109 |
+
# Helper to clean up the selected choice.
|
110 |
def clean_choice(choice):
|
111 |
if "Elon" in choice:
|
112 |
return "Elon Ma (Official)"
|
|
|
116 |
return "Mr. Shortreed (Official)"
|
117 |
return "Elon Ma (Official)"
|
118 |
|
119 |
+
# ChatInterface using OpenAI-style messages.
|
120 |
chatbot = gr.ChatInterface(
|
121 |
lambda msg, hist, char: respond(msg, hist, clean_choice(char)),
|
122 |
additional_inputs=[character],
|
123 |
+
type="messages"
|
|
|
124 |
)
|
125 |
|
126 |
demo.launch(share=True)
|