Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,22 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
#
|
|
|
|
|
|
|
|
|
|
| 4 |
def fruit_health_bot(message, history=[]):
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
"mango": "Mangoes are rich in antioxidants and support skin health."
|
| 10 |
-
}
|
| 11 |
-
message_lower = message.lower().strip()
|
| 12 |
-
for fruit in responses:
|
| 13 |
-
if fruit in message_lower:
|
| 14 |
-
return responses[fruit]
|
| 15 |
-
return "Hi there! 🍎 I'm FruitHealthGPT. Ask me about the health benefits of any fruit!"
|
| 16 |
|
| 17 |
-
# Create
|
| 18 |
iface = gr.ChatInterface(
|
| 19 |
fn=fruit_health_bot,
|
| 20 |
-
title="
|
| 21 |
-
description="Ask me about the health benefits of
|
| 22 |
)
|
| 23 |
|
| 24 |
iface.launch()
|
| 25 |
|
| 26 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load a small, free AI model from Hugging Face
|
| 5 |
+
generator = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.2")
|
| 6 |
+
|
| 7 |
+
# Define chatbot logic
|
| 8 |
def fruit_health_bot(message, history=[]):
|
| 9 |
+
prompt = f"You are FruitHealthGPT, a friendly expert on fruits and health benefits. Be concise and helpful.\nUser: {message}\nFruitHealthGPT:"
|
| 10 |
+
response = generator(prompt, max_new_tokens=100, do_sample=True, temperature=0.7)
|
| 11 |
+
answer = response[0]["generated_text"].split("FruitHealthGPT:")[-1].strip()
|
| 12 |
+
return answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Create the chat UI
|
| 15 |
iface = gr.ChatInterface(
|
| 16 |
fn=fruit_health_bot,
|
| 17 |
+
title="🍎 FruitHealthGPT",
|
| 18 |
+
description="Ask me about the health benefits of any fruit!"
|
| 19 |
)
|
| 20 |
|
| 21 |
iface.launch()
|
| 22 |
|
|
|