Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load a very small model so it runs quickly on CPU (free tier) | |
| generator = pipeline("text-generation", model="sshleifer/tiny-gpt2") | |
| def chat(user_input): | |
| try: | |
| response = generator( | |
| user_input, | |
| max_new_tokens=50, | |
| do_sample=True, | |
| top_p=0.9, | |
| temperature=0.8 | |
| ) | |
| # Remove the original prompt from the generated text | |
| reply = response[0]["generated_text"][len(user_input):].strip() | |
| return reply | |
| except Exception as e: | |
| return f"⚠️ Error: {str(e)}" | |
| iface = gr.Interface( | |
| fn=chat, | |
| inputs=gr.Textbox( | |
| placeholder="Type something...", | |
| lines=2, | |
| label="Your Question" | |
| ), | |
| outputs=gr.Textbox(label="AI Response"), | |
| title="🧠 Tiny AI Chatbot", | |
| description="A lightweight chatbot running on Hugging Face Spaces (Free CPU tier)" | |
| ) | |
| if __name__ == "__main__": | |
| # Hugging Face Spaces handles the server automatically | |
| iface.launch() | |