Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,30 +8,33 @@ import time
|
|
| 8 |
def load_model():
|
| 9 |
print("Loading Qwen3-0.6B model...")
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Load the model
|
| 28 |
-
|
| 29 |
-
tokenizer, model = load_model()
|
| 30 |
-
print(f"Model device: {model.device}")
|
| 31 |
-
print(f"Model dtype: {model.dtype}")
|
| 32 |
-
except Exception as e:
|
| 33 |
-
print(f"Error loading model: {e}")
|
| 34 |
-
tokenizer, model = None, None
|
| 35 |
|
| 36 |
def format_messages(history, new_message):
|
| 37 |
"""
|
|
@@ -53,7 +56,7 @@ def format_messages(history, new_message):
|
|
| 53 |
|
| 54 |
def generate_response(message, history, temperature=0.7, max_length=512):
|
| 55 |
"""
|
| 56 |
-
Generate a response using
|
| 57 |
"""
|
| 58 |
if tokenizer is None or model is None:
|
| 59 |
return "Model is not loaded properly. Please check the logs."
|
|
@@ -78,7 +81,7 @@ def generate_response(message, history, temperature=0.7, max_length=512):
|
|
| 78 |
**model_inputs,
|
| 79 |
max_new_tokens=max_length,
|
| 80 |
temperature=temperature,
|
| 81 |
-
do_sample=True,
|
| 82 |
top_p=0.9,
|
| 83 |
repetition_penalty=1.1,
|
| 84 |
eos_token_id=tokenizer.eos_token_id,
|
|
@@ -142,82 +145,97 @@ def retry_last_response(history, temperature, max_length):
|
|
| 142 |
|
| 143 |
return last_conversation
|
| 144 |
|
| 145 |
-
# Custom CSS for beautiful styling
|
| 146 |
custom_css = """
|
| 147 |
.gradio-container {
|
| 148 |
-
|
| 149 |
-
min-height: 100vh;
|
| 150 |
}
|
| 151 |
|
| 152 |
-
.
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
padding:
|
| 156 |
-
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
| 157 |
-
margin: 20px;
|
| 158 |
}
|
| 159 |
|
| 160 |
-
.
|
| 161 |
-
|
| 162 |
}
|
| 163 |
|
| 164 |
-
|
| 165 |
-
background:
|
| 166 |
border-radius: 15px;
|
| 167 |
-
padding:
|
| 168 |
-
height:
|
| 169 |
-
|
| 170 |
-
|
| 171 |
}
|
| 172 |
|
| 173 |
-
.
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
}
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
|
|
|
| 179 |
border: none !important;
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
padding: 12px 25px !important;
|
| 183 |
-
font-weight: 600 !important;
|
| 184 |
-
transition: all 0.3s ease !important;
|
| 185 |
}
|
| 186 |
|
| 187 |
-
.
|
| 188 |
-
|
| 189 |
-
|
|
|
|
| 190 |
}
|
| 191 |
|
| 192 |
.control-panel {
|
| 193 |
background: white;
|
| 194 |
-
padding:
|
| 195 |
-
border-radius:
|
| 196 |
-
|
| 197 |
-
|
| 198 |
}
|
| 199 |
|
| 200 |
-
.
|
| 201 |
-
background: #
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
| 203 |
}
|
| 204 |
|
| 205 |
-
.
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
}
|
| 208 |
|
| 209 |
-
.
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
}
|
| 216 |
|
| 217 |
.textbox {
|
| 218 |
-
border-radius:
|
| 219 |
-
padding: 15px !important;
|
| 220 |
border: 2px solid #e1e5e9 !important;
|
|
|
|
| 221 |
}
|
| 222 |
|
| 223 |
.textbox:focus {
|
|
@@ -225,151 +243,161 @@ custom_css = """
|
|
| 225 |
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
|
| 226 |
}
|
| 227 |
|
| 228 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 230 |
-webkit-background-clip: text;
|
| 231 |
-webkit-text-fill-color: transparent;
|
| 232 |
background-clip: text;
|
| 233 |
-
|
| 234 |
-
|
| 235 |
}
|
| 236 |
|
| 237 |
-
.
|
| 238 |
-
|
| 239 |
-
|
|
|
|
| 240 |
}
|
| 241 |
"""
|
| 242 |
|
| 243 |
-
# Create the Gradio interface
|
| 244 |
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
| 245 |
-
gr.Markdown(
|
| 246 |
-
"""
|
| 247 |
-
# π Qwen3-0.6B Chatbot
|
| 248 |
-
**Chat with Alibaba's advanced Qwen3-0.6B model!** Experience more fluent and intelligent conversations.
|
| 249 |
-
""",
|
| 250 |
-
elem_classes="markdown-container"
|
| 251 |
-
)
|
| 252 |
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
gr.
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
- Large model size download
|
| 259 |
-
- Hugging Face API limitations
|
| 260 |
-
- Insufficient resources
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
with gr.Row():
|
| 277 |
-
msg = gr.Textbox(
|
| 278 |
-
label="π Your message",
|
| 279 |
-
placeholder="Ask me anything..." if tokenizer and model else "Model is loading...",
|
| 280 |
-
lines=2,
|
| 281 |
-
scale=4,
|
| 282 |
-
container=False,
|
| 283 |
-
interactive=tokenizer is not None and model is not None
|
| 284 |
-
)
|
| 285 |
-
with gr.Column(scale=1):
|
| 286 |
-
submit_btn = gr.Button(
|
| 287 |
-
"Send π" if tokenizer and model else "Loading...",
|
| 288 |
-
size="lg",
|
| 289 |
-
interactive=tokenizer is not None and model is not None
|
| 290 |
)
|
| 291 |
-
|
| 292 |
-
with gr.Row():
|
| 293 |
-
clear_btn = gr.Button("ποΈ Clear Chat", size="sm")
|
| 294 |
-
retry_btn = gr.Button("π Retry", size="sm")
|
| 295 |
-
gr.HTML("""<div style="text-align: center; color: #666; font-size: 12px;">
|
| 296 |
-
Pro tip: Use Shift+Enter for new line, Enter to send
|
| 297 |
-
</div>""")
|
| 298 |
-
|
| 299 |
-
with gr.Column(scale=1):
|
| 300 |
-
with gr.Group(elem_classes="control-panel"):
|
| 301 |
-
gr.Markdown("### βοΈ Generation Settings")
|
| 302 |
-
|
| 303 |
-
temperature = gr.Slider(
|
| 304 |
-
minimum=0.1,
|
| 305 |
-
maximum=1.5,
|
| 306 |
-
value=0.7,
|
| 307 |
-
step=0.1,
|
| 308 |
-
label="ποΈ Temperature",
|
| 309 |
-
info="Lower = more deterministic, Higher = more creative"
|
| 310 |
-
)
|
| 311 |
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
gr.
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
submit_btn.click(
|
| 344 |
-
chat_interface,
|
| 345 |
-
inputs=[msg, chatbot, temperature, max_length],
|
| 346 |
-
outputs=[msg, chatbot]
|
| 347 |
-
)
|
| 348 |
-
|
| 349 |
-
clear_btn.click(
|
| 350 |
-
clear_chat,
|
| 351 |
-
outputs=[chatbot]
|
| 352 |
-
)
|
| 353 |
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
outputs=[chatbot]
|
| 358 |
-
)
|
| 359 |
-
|
| 360 |
-
# Additional examples
|
| 361 |
-
with gr.Accordion("π‘ Example Prompts", open=False):
|
| 362 |
gr.Examples(
|
| 363 |
examples=[
|
| 364 |
"Explain quantum computing in simple terms",
|
| 365 |
"Write a short poem about artificial intelligence",
|
| 366 |
"What are the benefits of renewable energy?",
|
| 367 |
"How do I learn programming effectively?",
|
| 368 |
-
"Tell me an interesting fact about space"
|
|
|
|
| 369 |
],
|
| 370 |
inputs=msg,
|
| 371 |
-
label="Click any example to
|
|
|
|
| 372 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
|
| 374 |
if __name__ == "__main__":
|
| 375 |
demo.launch(
|
|
|
|
| 8 |
def load_model():
|
| 9 |
print("Loading Qwen3-0.6B model...")
|
| 10 |
|
| 11 |
+
try:
|
| 12 |
+
# Load tokenizer and model
|
| 13 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 14 |
+
"Qwen/Qwen3-0.6B",
|
| 15 |
+
trust_remote_code=True
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 19 |
+
"Qwen/Qwen3-0.6B",
|
| 20 |
+
torch_dtype=torch.float16,
|
| 21 |
+
device_map="auto",
|
| 22 |
+
trust_remote_code=True
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
print("Model loaded successfully!")
|
| 26 |
+
return tokenizer, model
|
| 27 |
+
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print(f"Error loading model: {e}")
|
| 30 |
+
# Fallback to a smaller model if Qwen fails
|
| 31 |
+
print("Trying fallback model...")
|
| 32 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
|
| 33 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
|
| 34 |
+
return tokenizer, model
|
| 35 |
|
| 36 |
# Load the model
|
| 37 |
+
tokenizer, model = load_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def format_messages(history, new_message):
|
| 40 |
"""
|
|
|
|
| 56 |
|
| 57 |
def generate_response(message, history, temperature=0.7, max_length=512):
|
| 58 |
"""
|
| 59 |
+
Generate a response using the model
|
| 60 |
"""
|
| 61 |
if tokenizer is None or model is None:
|
| 62 |
return "Model is not loaded properly. Please check the logs."
|
|
|
|
| 81 |
**model_inputs,
|
| 82 |
max_new_tokens=max_length,
|
| 83 |
temperature=temperature,
|
| 84 |
+
do_sample=True if temperature > 0.1 else False,
|
| 85 |
top_p=0.9,
|
| 86 |
repetition_penalty=1.1,
|
| 87 |
eos_token_id=tokenizer.eos_token_id,
|
|
|
|
| 145 |
|
| 146 |
return last_conversation
|
| 147 |
|
| 148 |
+
# Custom CSS for beautiful styling with better layout
|
| 149 |
custom_css = """
|
| 150 |
.gradio-container {
|
| 151 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
|
|
| 152 |
}
|
| 153 |
|
| 154 |
+
.main-container {
|
| 155 |
+
max-width: 1200px !important;
|
| 156 |
+
margin: 0 auto !important;
|
| 157 |
+
padding: 20px !important;
|
|
|
|
|
|
|
| 158 |
}
|
| 159 |
|
| 160 |
+
.chat-column {
|
| 161 |
+
min-height: 600px;
|
| 162 |
}
|
| 163 |
|
| 164 |
+
.control-column {
|
| 165 |
+
background: #f8f9fa;
|
| 166 |
border-radius: 15px;
|
| 167 |
+
padding: 20px;
|
| 168 |
+
height: fit-content;
|
| 169 |
+
position: sticky;
|
| 170 |
+
top: 20px;
|
| 171 |
}
|
| 172 |
|
| 173 |
+
.chatbot-container {
|
| 174 |
+
border: 2px solid #e1e5e9;
|
| 175 |
+
border-radius: 15px;
|
| 176 |
+
padding: 0;
|
| 177 |
+
overflow: hidden;
|
| 178 |
+
background: white;
|
| 179 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
| 180 |
}
|
| 181 |
|
| 182 |
+
#chatbot {
|
| 183 |
+
min-height: 500px;
|
| 184 |
+
max-height: 500px;
|
| 185 |
border: none !important;
|
| 186 |
+
background: white !important;
|
| 187 |
+
padding: 20px !important;
|
|
|
|
|
|
|
|
|
|
| 188 |
}
|
| 189 |
|
| 190 |
+
.input-container {
|
| 191 |
+
background: white;
|
| 192 |
+
padding: 20px;
|
| 193 |
+
border-top: 1px solid #e1e5e9;
|
| 194 |
}
|
| 195 |
|
| 196 |
.control-panel {
|
| 197 |
background: white;
|
| 198 |
+
padding: 20px;
|
| 199 |
+
border-radius: 10px;
|
| 200 |
+
margin-bottom: 20px;
|
| 201 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
| 202 |
}
|
| 203 |
|
| 204 |
+
.model-info-card {
|
| 205 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 206 |
+
color: white;
|
| 207 |
+
padding: 20px;
|
| 208 |
+
border-radius: 10px;
|
| 209 |
+
margin-top: 20px;
|
| 210 |
}
|
| 211 |
|
| 212 |
+
.gr-button {
|
| 213 |
+
background: linear-gradient(45deg, #667eea, #764ba2) !important;
|
| 214 |
+
border: none !important;
|
| 215 |
+
color: white !important;
|
| 216 |
+
border-radius: 10px !important;
|
| 217 |
+
padding: 10px 20px !important;
|
| 218 |
+
font-weight: 600 !important;
|
| 219 |
+
margin: 5px !important;
|
| 220 |
}
|
| 221 |
|
| 222 |
+
.gr-button:hover {
|
| 223 |
+
transform: translateY(-2px);
|
| 224 |
+
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
.clear-btn {
|
| 228 |
+
background: linear-gradient(45deg, #ff6b6b, #ee5a24) !important;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
.retry-btn {
|
| 232 |
+
background: linear-gradient(45deg, #00b894, #00a085) !important;
|
| 233 |
}
|
| 234 |
|
| 235 |
.textbox {
|
| 236 |
+
border-radius: 10px !important;
|
|
|
|
| 237 |
border: 2px solid #e1e5e9 !important;
|
| 238 |
+
padding: 15px !important;
|
| 239 |
}
|
| 240 |
|
| 241 |
.textbox:focus {
|
|
|
|
| 243 |
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
|
| 244 |
}
|
| 245 |
|
| 246 |
+
.slider-container {
|
| 247 |
+
margin: 15px 0;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
.examples-panel {
|
| 251 |
+
background: white;
|
| 252 |
+
padding: 15px;
|
| 253 |
+
border-radius: 10px;
|
| 254 |
+
margin-top: 20px;
|
| 255 |
+
border: 1px solid #e1e5e9;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
.header {
|
| 259 |
+
text-align: center;
|
| 260 |
+
margin-bottom: 30px !important;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
.header h1 {
|
| 264 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 265 |
-webkit-background-clip: text;
|
| 266 |
-webkit-text-fill-color: transparent;
|
| 267 |
background-clip: text;
|
| 268 |
+
font-size: 2.5em !important;
|
| 269 |
+
margin-bottom: 10px !important;
|
| 270 |
}
|
| 271 |
|
| 272 |
+
.header p {
|
| 273 |
+
color: #666;
|
| 274 |
+
font-size: 1.2em;
|
| 275 |
+
margin: 0 !important;
|
| 276 |
}
|
| 277 |
"""
|
| 278 |
|
| 279 |
+
# Create the Gradio interface with better layout
|
| 280 |
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
|
| 282 |
+
with gr.Column(elem_classes="main-container"):
|
| 283 |
+
# Header
|
| 284 |
+
with gr.Column(elem_classes="header"):
|
| 285 |
+
gr.Markdown("# π€ Qwen3-0.6B Chatbot")
|
| 286 |
+
gr.Markdown("Chat with Alibaba's advanced Qwen3-0.6B model! Experience fluent and intelligent conversations.")
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
+
with gr.Row(equal_height=False):
|
| 289 |
+
# Left Column - Chat Interface (Larger)
|
| 290 |
+
with gr.Column(scale=3, elem_classes="chat-column"):
|
| 291 |
+
with gr.Column(elem_classes="chatbot-container"):
|
| 292 |
+
chatbot = gr.Chatbot(
|
| 293 |
+
value=[["Hello! How can I help you today?", ""]],
|
| 294 |
+
label="π¬ Chat with Qwen3",
|
| 295 |
+
elem_id="chatbot",
|
| 296 |
+
show_copy_button=True,
|
| 297 |
+
avatar_images=("π€", "π€"),
|
| 298 |
+
height=500,
|
| 299 |
+
show_label=True,
|
| 300 |
+
container=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
|
| 303 |
+
with gr.Column(elem_classes="input-container"):
|
| 304 |
+
with gr.Row():
|
| 305 |
+
msg = gr.Textbox(
|
| 306 |
+
label="",
|
| 307 |
+
placeholder="Type your message here...",
|
| 308 |
+
lines=2,
|
| 309 |
+
scale=4,
|
| 310 |
+
container=False,
|
| 311 |
+
show_label=False
|
| 312 |
+
)
|
| 313 |
+
with gr.Column(scale=1):
|
| 314 |
+
submit_btn = gr.Button("Send π", size="lg")
|
| 315 |
+
|
| 316 |
+
with gr.Row():
|
| 317 |
+
clear_btn = gr.Button("ποΈ Clear Chat", elem_classes="clear-btn")
|
| 318 |
+
retry_btn = gr.Button("π Retry Last", elem_classes="retry-btn")
|
| 319 |
+
gr.HTML("""<div style="flex: 1; text-align: center; color: #666; font-size: 12px; padding: 10px;">
|
| 320 |
+
π‘ Tip: Press Enter to send, Shift+Enter for new line
|
| 321 |
+
</div>""")
|
| 322 |
|
| 323 |
+
# Right Column - Controls (Smaller)
|
| 324 |
+
with gr.Column(scale=1, elem_classes="control-column"):
|
| 325 |
+
with gr.Column(elem_classes="control-panel"):
|
| 326 |
+
gr.Markdown("### βοΈ Generation Settings")
|
| 327 |
+
|
| 328 |
+
temperature = gr.Slider(
|
| 329 |
+
minimum=0.1,
|
| 330 |
+
maximum=1.5,
|
| 331 |
+
value=0.7,
|
| 332 |
+
step=0.1,
|
| 333 |
+
label="Temperature",
|
| 334 |
+
info="Controls creativity: lower = more focused, higher = more creative"
|
| 335 |
+
)
|
| 336 |
+
|
| 337 |
+
max_length = gr.Slider(
|
| 338 |
+
minimum=64,
|
| 339 |
+
maximum=1024,
|
| 340 |
+
value=256,
|
| 341 |
+
step=64,
|
| 342 |
+
label="Max Response Length",
|
| 343 |
+
info="Maximum tokens in generated response"
|
| 344 |
+
)
|
| 345 |
|
| 346 |
+
with gr.Column(elem_classes="model-info-card"):
|
| 347 |
+
gr.Markdown("### βΉοΈ About This Model")
|
| 348 |
+
gr.Markdown("""
|
| 349 |
+
**Model:** Qwen3-0.6B
|
| 350 |
+
**Provider:** Alibaba Group
|
| 351 |
+
**Context:** 128K tokens
|
| 352 |
+
**Languages:** Multilingual
|
| 353 |
+
|
| 354 |
+
β¨ **Capabilities:**
|
| 355 |
+
- Natural conversations
|
| 356 |
+
- Creative writing
|
| 357 |
+
- Problem solving
|
| 358 |
+
- Code generation
|
| 359 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
+
# Examples Section
|
| 362 |
+
with gr.Column(elem_classes="examples-panel"):
|
| 363 |
+
gr.Markdown("### π‘ Try These Examples")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
gr.Examples(
|
| 365 |
examples=[
|
| 366 |
"Explain quantum computing in simple terms",
|
| 367 |
"Write a short poem about artificial intelligence",
|
| 368 |
"What are the benefits of renewable energy?",
|
| 369 |
"How do I learn programming effectively?",
|
| 370 |
+
"Tell me an interesting fact about space exploration",
|
| 371 |
+
"Help me plan a healthy weekly meal plan"
|
| 372 |
],
|
| 373 |
inputs=msg,
|
| 374 |
+
label="Click any example to start chatting!",
|
| 375 |
+
examples_per_page=6
|
| 376 |
)
|
| 377 |
+
|
| 378 |
+
# Event handlers
|
| 379 |
+
submit_event = msg.submit(
|
| 380 |
+
chat_interface,
|
| 381 |
+
inputs=[msg, chatbot, temperature, max_length],
|
| 382 |
+
outputs=[msg, chatbot]
|
| 383 |
+
)
|
| 384 |
+
|
| 385 |
+
submit_btn.click(
|
| 386 |
+
chat_interface,
|
| 387 |
+
inputs=[msg, chatbot, temperature, max_length],
|
| 388 |
+
outputs=[msg, chatbot]
|
| 389 |
+
)
|
| 390 |
+
|
| 391 |
+
clear_btn.click(
|
| 392 |
+
clear_chat,
|
| 393 |
+
outputs=[chatbot]
|
| 394 |
+
)
|
| 395 |
+
|
| 396 |
+
retry_btn.click(
|
| 397 |
+
retry_last_response,
|
| 398 |
+
inputs=[chatbot, temperature, max_length],
|
| 399 |
+
outputs=[chatbot]
|
| 400 |
+
)
|
| 401 |
|
| 402 |
if __name__ == "__main__":
|
| 403 |
demo.launch(
|