Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,31 +10,37 @@ from transformers import pipeline
|
|
| 10 |
generator = pipeline("text-generation", model="HuggingFaceTB/SmolLM-1.7B-Instruct")
|
| 11 |
|
| 12 |
def chat_respond(message, history):
|
| 13 |
-
# Format the
|
| 14 |
prompt = ""
|
| 15 |
-
for
|
| 16 |
-
|
|
|
|
| 17 |
prompt += f"User: {message}\nAssistant:"
|
| 18 |
|
| 19 |
-
# Generate
|
| 20 |
results = generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)
|
| 21 |
|
| 22 |
-
#
|
| 23 |
full_text = results['generated_text']
|
| 24 |
response = full_text.split("Assistant:")[-1].strip()
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
# Build a clean
|
| 28 |
-
with gr.Blocks(
|
| 29 |
-
gr.Markdown("#
|
| 30 |
-
gr.Markdown("Welcome to
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
clear_btn="🗑️ Clear Chat",
|
| 38 |
-
)
|
| 39 |
|
| 40 |
-
demo.launch()
|
|
|
|
| 10 |
generator = pipeline("text-generation", model="HuggingFaceTB/SmolLM-1.7B-Instruct")
|
| 11 |
|
| 12 |
def chat_respond(message, history):
|
| 13 |
+
# Format the modern message list history into text for SmolLM
|
| 14 |
prompt = ""
|
| 15 |
+
for msg in history:
|
| 16 |
+
role_label = "User" if msg["role"] == "user" else "Assistant"
|
| 17 |
+
prompt += f"{role_label}: {msg['content']}\n"
|
| 18 |
prompt += f"User: {message}\nAssistant:"
|
| 19 |
|
| 20 |
+
# Generate the text tokens
|
| 21 |
results = generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)
|
| 22 |
|
| 23 |
+
# Clean up the output string
|
| 24 |
full_text = results['generated_text']
|
| 25 |
response = full_text.split("Assistant:")[-1].strip()
|
| 26 |
+
|
| 27 |
+
# Return history with the new assistant message appended
|
| 28 |
+
history.append({"role": "user", "content": message})
|
| 29 |
+
history.append({"role": "assistant", "content": response})
|
| 30 |
+
return "", history
|
| 31 |
|
| 32 |
+
# Build a clean, modern Chat interface utilizing Gradio 6 styling
|
| 33 |
+
with gr.Blocks() as demo:
|
| 34 |
+
gr.Markdown("# 🐨 Raller Magnium AI")
|
| 35 |
+
gr.Markdown("Welcome to our small AI system, hope you like it. Powered by raller.pro.")
|
| 36 |
+
|
| 37 |
+
# Modern Gradio 6 chatbot component setup with message system format
|
| 38 |
+
chatbot = gr.Chatbot(type="messages")
|
| 39 |
+
msg_input = gr.Textbox(placeholder="Ask Raller Magnium anything...", container=False, scale=7)
|
| 40 |
|
| 41 |
+
# Handle the submission loop cleanly
|
| 42 |
+
msg_input.submit(chat_respond, inputs=[msg_input, chatbot], outputs=[msg_input, chatbot])
|
| 43 |
+
|
| 44 |
+
# Pass theme variables to launch directly per Gradio 6 requirements
|
| 45 |
+
demo.launch(theme=gr.themes.Soft())
|
|
|
|
|
|
|
| 46 |
|
|
|