Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,3 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
-
|
| 4 |
-
# ✅ Connect to Hugging Face API
|
| 5 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
-
|
| 7 |
-
# ✅ Custom System Prompt
|
| 8 |
-
SYSTEM_PROMPT = (
|
| 9 |
-
"You are an AI assistant named Bandar AI. "
|
| 10 |
-
"If you do not understand the question, say: 'I don't understand.'"
|
| 11 |
-
)
|
| 12 |
-
|
| 13 |
-
# ✅ Chatbot Response Function
|
| 14 |
-
def chatbot_response(user_input):
|
| 15 |
-
messages = [
|
| 16 |
-
{"role": "system", "content": SYSTEM_PROMPT},
|
| 17 |
-
{"role": "user", "content": user_input}
|
| 18 |
-
]
|
| 19 |
-
|
| 20 |
-
response = client.chat_completion(messages, max_tokens=150, temperature=0.7)
|
| 21 |
-
|
| 22 |
-
# Extract the response text
|
| 23 |
-
try:
|
| 24 |
-
reply = response.choices[0].message["content"]
|
| 25 |
-
except (KeyError, IndexError):
|
| 26 |
-
reply = "I don't understand." # Fallback response
|
| 27 |
-
|
| 28 |
-
return reply
|
| 29 |
-
|
| 30 |
-
# ✅ Gradio UI with Modern Design
|
| 31 |
-
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
|
| 32 |
-
gr.Markdown(
|
| 33 |
-
"""
|
| 34 |
-
# 🤖 Bandar AI - Smart Chatbot
|
| 35 |
-
### 💬 Ask me anything, and I will include your name in my responses!
|
| 36 |
-
""",
|
| 37 |
-
elem_id="title"
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
chatbot = gr.Chatbot(label="Bandar AI", bubble_full_width=True)
|
| 41 |
-
|
| 42 |
-
with gr.Row():
|
| 43 |
-
user_input = gr.Textbox(placeholder="Type your message here...", label="Your Message", scale=8)
|
| 44 |
-
send_button = gr.Button("Send", variant="primary", scale=2)
|
| 45 |
-
|
| 46 |
-
with gr.Row():
|
| 47 |
-
clear_button = gr.Button("Clear Chat", variant="secondary")
|
| 48 |
-
|
| 49 |
-
# Event Handlers
|
| 50 |
-
send_button.click(chatbot_response, inputs=user_input, outputs=chatbot)
|
| 51 |
-
user_input.submit(chatbot_response, inputs=user_input, outputs=chatbot)
|
| 52 |
-
clear_button.click(lambda: "", outputs=chatbot) # Clears the chat
|
| 53 |
-
|
| 54 |
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
gr.load("models/HuggingFaceH4/zephyr-7b-beta").launch()
|