File size: 775 Bytes
99c91a8 810eb66 99c91a8 810eb66 17b8337 810eb66 99c91a8 810eb66 99c91a8 810eb66 99c91a8 17b8337 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import gradio as gr
from transformers import pipeline
# Load a small, free AI model from Hugging Face
generator = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.2")
# Define chatbot logic
def fruit_health_bot(message, history=[]):
prompt = f"You are FruitHealthGPT, a friendly expert on fruits and health benefits. Be concise and helpful.\nUser: {message}\nFruitHealthGPT:"
response = generator(prompt, max_new_tokens=100, do_sample=True, temperature=0.7)
answer = response[0]["generated_text"].split("FruitHealthGPT:")[-1].strip()
return answer
# Create the chat UI
iface = gr.ChatInterface(
fn=fruit_health_bot,
title="🍎 FruitHealthGPT",
description="Ask me about the health benefits of any fruit!"
)
iface.launch()
|