Download app.py from Aarham/SuperBot: direct link, hf CLI and curl.
- Browser
- Download file 1.58 kB
-
https://huggingface.co/spaces/Aarham/SuperBot/resolve/main/app.py
- Command line
-
hf download hf://spaces/Aarham/SuperBot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Aarham/SuperBot/resolve/main/app.py
1.58 kB
| import spaces | |
| import gradio as gr | |
| from transformers import pipeline | |
| # Downloads & runs YOUR model directly on Hugging Face's big cloud server (0 MB on your PC!) | |
| ai_brain = pipeline("text-generation", model="Qwen/Qwen2.5-0.5B-Instruct") | |
| def superbot_reply(message, history, uploaded_file): | |
| extra_context = "" | |
| # Reads uploaded file in temporary RAM and discards it immediately so the server never overflows! | |
| if uploaded_file is not None: | |
| with open(uploaded_file.name, "r", encoding="utf-8", errors="ignore") as f: | |
| extra_context = f"\n\n[User File Content]:\n{f.read()[:4000]}" | |
| messages = [ | |
| {"role": "system", "content": "You are SuperBot, an advanced AI created by the Founder. Think step-by-step and give clear, helpful answers."} | |
| ] | |
| # Add recent conversation memory | |
| for user_msg, bot_msg in history[-5:]: | |
| messages.append({"role": "user", "content": user_msg}) | |
| messages.append({"role": "assistant", "content": bot_msg}) | |
| messages.append({"role": "user", "content": message + extra_context}) | |
| result = ai_brain(messages, max_new_tokens=150) | |
| return result[0]["generated_text"][-1]["content"] | |
| demo = gr.ChatInterface( | |
| fn=superbot_reply, | |
| additional_inputs=[ | |
| gr.File(label="Optional File Upload (Auto-wiped after reply so server never overflows)") | |
| ], | |
| title="🤖 SuperBot AI — Cloud Server Edition", | |
| description="Built by the Founder. Runs 100% on cloud servers with zero local PC storage!" | |
| ) | |
| demo.launch() | |