Spaces:
Running
Running
SkyNetWalker
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,6 @@ client = OpenAI(
|
|
16 |
|
17 |
print("Client initialized.")
|
18 |
|
19 |
-
# Pre-set system prompts
|
20 |
SYSTEM_PROMPTS = {
|
21 |
"General Assistant": "You are a helpful, respectful and honest assistant. Always provide accurate information and admit when you're not sure about something.",
|
22 |
"Code Helper": "You are a programming assistant. Help users with coding questions, debugging, and best practices. Provide clear explanations and code examples when appropriate.",
|
@@ -36,7 +35,6 @@ def respond(
|
|
36 |
print(f"Received message: {message}")
|
37 |
print(f"History: {history}")
|
38 |
|
39 |
-
# Use custom prompt if provided, otherwise use selected preset
|
40 |
system_message = custom_prompt if custom_prompt.strip() else SYSTEM_PROMPTS[preset_prompt]
|
41 |
|
42 |
print(f"System message: {system_message}")
|
@@ -73,10 +71,6 @@ def respond(
|
|
73 |
|
74 |
print("Completed response generation.")
|
75 |
|
76 |
-
chatbot = gr.Chatbot(height=400)
|
77 |
-
|
78 |
-
print("Chatbot interface created.")
|
79 |
-
|
80 |
models = [
|
81 |
"PowerInfer/SmallThinker-3B-Preview",
|
82 |
"Qwen/QwQ-32B-Preview",
|
@@ -89,55 +83,94 @@ with gr.Blocks() as demo:
|
|
89 |
gr.Markdown("# LLM Test")
|
90 |
|
91 |
with gr.Row():
|
92 |
-
# Model selection at the top
|
93 |
model_dropdown = gr.Dropdown(
|
94 |
choices=models,
|
95 |
value=models[0],
|
96 |
label="Select Model:"
|
97 |
)
|
98 |
-
|
99 |
-
#
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
choices=list(SYSTEM_PROMPTS.keys()),
|
106 |
-
value=list(SYSTEM_PROMPTS.keys())[0],
|
107 |
-
label="Select System Prompt:"
|
108 |
-
),
|
109 |
-
gr.Textbox(
|
110 |
-
value="",
|
111 |
-
label="Custom System Prompt (leaves blank to use preset):",
|
112 |
-
lines=2
|
113 |
-
),
|
114 |
-
# Other parameters
|
115 |
-
gr.Slider(
|
116 |
-
minimum=1,
|
117 |
-
maximum=4096,
|
118 |
-
value=1024,
|
119 |
-
step=1,
|
120 |
-
label="Max new tokens:"
|
121 |
-
),
|
122 |
-
gr.Slider(
|
123 |
-
minimum=0.1,
|
124 |
-
maximum=1.0,
|
125 |
-
value=0.3,
|
126 |
-
step=0.1,
|
127 |
-
label="Temperature:"
|
128 |
-
),
|
129 |
-
gr.Slider(
|
130 |
-
minimum=0.1,
|
131 |
-
maximum=1.0,
|
132 |
-
value=0.95,
|
133 |
-
step=0.05,
|
134 |
-
label="Top-P:"
|
135 |
-
),
|
136 |
-
model_dropdown,
|
137 |
-
],
|
138 |
-
fill_height=True,
|
139 |
-
chatbot=chatbot,
|
140 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
print("Gradio interface initialized.")
|
143 |
|
|
|
16 |
|
17 |
print("Client initialized.")
|
18 |
|
|
|
19 |
SYSTEM_PROMPTS = {
|
20 |
"General Assistant": "You are a helpful, respectful and honest assistant. Always provide accurate information and admit when you're not sure about something.",
|
21 |
"Code Helper": "You are a programming assistant. Help users with coding questions, debugging, and best practices. Provide clear explanations and code examples when appropriate.",
|
|
|
35 |
print(f"Received message: {message}")
|
36 |
print(f"History: {history}")
|
37 |
|
|
|
38 |
system_message = custom_prompt if custom_prompt.strip() else SYSTEM_PROMPTS[preset_prompt]
|
39 |
|
40 |
print(f"System message: {system_message}")
|
|
|
71 |
|
72 |
print("Completed response generation.")
|
73 |
|
|
|
|
|
|
|
|
|
74 |
models = [
|
75 |
"PowerInfer/SmallThinker-3B-Preview",
|
76 |
"Qwen/QwQ-32B-Preview",
|
|
|
83 |
gr.Markdown("# LLM Test")
|
84 |
|
85 |
with gr.Row():
|
|
|
86 |
model_dropdown = gr.Dropdown(
|
87 |
choices=models,
|
88 |
value=models[0],
|
89 |
label="Select Model:"
|
90 |
)
|
91 |
+
|
92 |
+
# Create the chat components separately
|
93 |
+
chatbot = gr.Chatbot(height=400)
|
94 |
+
msg = gr.Textbox(
|
95 |
+
show_label=False,
|
96 |
+
placeholder="Enter text and press enter",
|
97 |
+
container=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
)
|
99 |
+
clear = gr.Button("Clear")
|
100 |
+
|
101 |
+
# Additional inputs
|
102 |
+
with gr.Accordion("Configuration", open=False):
|
103 |
+
preset_prompt = gr.Dropdown(
|
104 |
+
choices=list(SYSTEM_PROMPTS.keys()),
|
105 |
+
value=list(SYSTEM_PROMPTS.keys())[0],
|
106 |
+
label="Select System Prompt:"
|
107 |
+
)
|
108 |
+
custom_prompt = gr.Textbox(
|
109 |
+
value="",
|
110 |
+
label="Custom System Prompt (leaves blank to use preset):",
|
111 |
+
lines=2
|
112 |
+
)
|
113 |
+
max_tokens = gr.Slider(
|
114 |
+
minimum=1,
|
115 |
+
maximum=4096,
|
116 |
+
value=1024,
|
117 |
+
step=1,
|
118 |
+
label="Max new tokens:"
|
119 |
+
)
|
120 |
+
temperature = gr.Slider(
|
121 |
+
minimum=0.1,
|
122 |
+
maximum=1.0,
|
123 |
+
value=0.3,
|
124 |
+
step=0.1,
|
125 |
+
label="Temperature:"
|
126 |
+
)
|
127 |
+
top_p = gr.Slider(
|
128 |
+
minimum=0.1,
|
129 |
+
maximum=1.0,
|
130 |
+
value=0.95,
|
131 |
+
step=0.05,
|
132 |
+
label="Top-P:"
|
133 |
+
)
|
134 |
+
|
135 |
+
# Set up the chat functionality
|
136 |
+
def user(user_message, history):
|
137 |
+
return "", history + [[user_message, None]]
|
138 |
+
|
139 |
+
def bot(
|
140 |
+
history,
|
141 |
+
preset_prompt,
|
142 |
+
custom_prompt,
|
143 |
+
max_tokens,
|
144 |
+
temperature,
|
145 |
+
top_p,
|
146 |
+
model_name
|
147 |
+
):
|
148 |
+
history[-1][1] = ""
|
149 |
+
for character in respond(
|
150 |
+
history[-1][0],
|
151 |
+
history[:-1],
|
152 |
+
preset_prompt,
|
153 |
+
custom_prompt,
|
154 |
+
max_tokens,
|
155 |
+
temperature,
|
156 |
+
top_p,
|
157 |
+
model_name
|
158 |
+
):
|
159 |
+
history[-1][1] = character
|
160 |
+
yield history
|
161 |
+
|
162 |
+
msg.submit(
|
163 |
+
user,
|
164 |
+
[msg, chatbot],
|
165 |
+
[msg, chatbot],
|
166 |
+
queue=False
|
167 |
+
).then(
|
168 |
+
bot,
|
169 |
+
[chatbot, preset_prompt, custom_prompt, max_tokens, temperature, top_p, model_dropdown],
|
170 |
+
chatbot
|
171 |
+
)
|
172 |
+
|
173 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
174 |
|
175 |
print("Gradio interface initialized.")
|
176 |
|