Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,41 +6,31 @@
|
|
| 6 |
import gradio as gr
|
| 7 |
from transformers import pipeline
|
| 8 |
|
| 9 |
-
# Load the SmolLM 1.7B Instruct model
|
| 10 |
generator = pipeline("text-generation", model="HuggingFaceTB/SmolLM-1.7B-Instruct")
|
| 11 |
|
| 12 |
def chat_respond(message, history):
|
| 13 |
-
# Format
|
| 14 |
prompt = ""
|
| 15 |
-
for
|
| 16 |
-
|
| 17 |
-
prompt += f"{role_label}: {msg['content']}\n"
|
| 18 |
prompt += f"User: {message}\nAssistant:"
|
| 19 |
|
| 20 |
-
# Generate
|
| 21 |
results = generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)
|
| 22 |
|
| 23 |
-
#
|
| 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 |
-
#
|
| 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 |
-
#
|
| 38 |
-
|
| 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 |
-
#
|
| 45 |
demo.launch(theme=gr.themes.Soft())
|
| 46 |
-
|
|
|
|
| 6 |
import gradio as gr
|
| 7 |
from transformers import pipeline
|
| 8 |
|
| 9 |
+
# Load the SmolLM 1.7B Instruct model cleanly
|
| 10 |
generator = pipeline("text-generation", model="HuggingFaceTB/SmolLM-1.7B-Instruct")
|
| 11 |
|
| 12 |
def chat_respond(message, history):
|
| 13 |
+
# Format basic text history for the AI engine
|
| 14 |
prompt = ""
|
| 15 |
+
for user_msg, ai_msg in history:
|
| 16 |
+
prompt += f"User: {user_msg}\nAssistant: {ai_msg}\n"
|
|
|
|
| 17 |
prompt += f"User: {message}\nAssistant:"
|
| 18 |
|
| 19 |
+
# Generate response string tokens
|
| 20 |
results = generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)
|
| 21 |
|
| 22 |
+
# Extract only the text that follows the final Assistant label
|
| 23 |
full_text = results['generated_text']
|
| 24 |
response = full_text.split("Assistant:")[-1].strip()
|
| 25 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
# Create the clean, error-free chatbot block layout
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
gr.Markdown("# 🐨 Raller Magnium AI")
|
| 30 |
gr.Markdown("Welcome to our small AI system, hope you like it. Powered by raller.pro.")
|
| 31 |
|
| 32 |
+
# The universal ChatInterface engine built into Gradio
|
| 33 |
+
gr.ChatInterface(fn=chat_respond)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
# Launch with the soft UI theme cleanly applied
|
| 36 |
demo.launch(theme=gr.themes.Soft())
|
|
|