Download app.py from An-Egoistic-Developer-Full-Of-Knowledge/GRADIO: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/An-Egoistic-Developer-Full-Of-Knowledge/GRADIO/resolve/main/app.py
- Command line
-
hf download hf://spaces/An-Egoistic-Developer-Full-Of-Knowledge/GRADIO/app.py
-
curl -L -o app.py https://huggingface.co/spaces/An-Egoistic-Developer-Full-Of-Knowledge/GRADIO/resolve/main/app.py
1.09 kB
| import gradio as gr | |
| from transformers import pipeline | |
| # ✅ Use a lightweight, always-free model | |
| jarvis = pipeline("text2text-generation", model="google/flan-t5-small") | |
| # Function to handle messages (compatible with new Gradio) | |
| def chat(message, history): | |
| # Reconstruct a text-based chat history | |
| context = "" | |
| for h in history: | |
| context += f"User: {h['content']}\nJarvis: {h.get('response', '')}\n" | |
| context += f"User: {message}\nJarvis:" | |
| # Generate response | |
| response = jarvis(context, max_new_tokens=128, temperature=0.7, do_sample=True) | |
| reply = response[0]["generated_text"] | |
| # Return message in new Gradio "messages" format | |
| history.append({"role": "user", "content": message}) | |
| history.append({"role": "assistant", "content": reply}) | |
| return "", history | |
| # Gradio Chat Interface (new style) | |
| gr.ChatInterface( | |
| fn=chat, | |
| title="Jarvis AI V2", | |
| description="Your personal AI assistant — accessible anywhere in the world.", | |
| theme="soft", | |
| type="messages", # 👈 important to avoid tuple errors | |
| ).launch(share=True) | |