Download app.py from SmartCon/README: direct link, hf CLI and curl.
- Browser
- Download file 775 Bytes
-
https://huggingface.co/spaces/SmartCon/README/resolve/main/app.py
- Command line
-
hf download hf://spaces/SmartCon/README/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SmartCon/README/resolve/main/app.py
775 Bytes
| 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() | |