import gradio as gr from transformers import pipeline # ✅ Open, small model that works without login pipe = pipeline("text-generation", model="facebook/opt-350m") def solve_question(question: str) -> str: try: result = pipe(question, max_new_tokens=100, temperature=0.7, do_sample=True) return result[0]["generated_text"] except Exception as e: return f"Error: {str(e)}" with gr.Blocks() as demo: gr.Markdown("## 🤖 Unit 4 Agent - OPT-350M (Open, No Login Needed)") question = gr.Textbox(label="Ask a Question", placeholder="Type your question here...") output = gr.Textbox(label="Answer") run_btn = gr.Button("Run Agent") run_btn.click(fn=solve_question, inputs=question, outputs=output) if __name__ == "__main__": demo.launch()