Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,21 @@
|
|
| 1 |
-
import os
|
| 2 |
-
os.system("pip install transformers torch accelerate gradio") # Install dependencies
|
| 3 |
-
|
| 4 |
import gradio as gr
|
| 5 |
from transformers import pipeline
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
chatbot_pipeline = pipeline("text-generation", model="
|
| 9 |
-
|
| 10 |
-
# Chatbot function
|
| 11 |
-
def chat_response(history, user_input):
|
| 12 |
-
if not user_input.strip():
|
| 13 |
-
return history + [{"role": "user", "content": user_input}, {"role": "assistant", "content": "Please enter a valid message."}], ""
|
| 14 |
-
|
| 15 |
-
bot_reply = chatbot_pipeline(user_input)[0]["generated_text"]
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
return
|
| 21 |
|
| 22 |
# Gradio UI
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
submit_button.click(chat_response, inputs=[chatbot, user_input], outputs=[chatbot, user_input])
|
| 31 |
-
user_input.submit(chat_response, inputs=[chatbot, user_input], outputs=[chatbot, user_input])
|
| 32 |
|
| 33 |
# Run on Hugging Face Spaces
|
| 34 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Use a simple, fast Hugging Face model
|
| 5 |
+
chatbot_pipeline = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-alpha")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Function to generate a chatbot response
|
| 8 |
+
def chat_response(user_input):
|
| 9 |
+
response = chatbot_pipeline(user_input, max_length=100)[0]["generated_text"]
|
| 10 |
+
return response
|
| 11 |
|
| 12 |
# Gradio UI
|
| 13 |
+
demo = gr.Interface(
|
| 14 |
+
fn=chat_response,
|
| 15 |
+
inputs="text",
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="🤖 Bandar AI Model"
|
| 18 |
+
)
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Run on Hugging Face Spaces
|
| 21 |
if __name__ == "__main__":
|