import os import gradio as gr from smolagents import CodeAgent from smolagents.models import OpenAIModel def run_hello_world(api_key): if not api_key: return "Please enter your OpenAI API key." os.environ["OPENAI_API_KEY"] = api_key try: # ✅ FIX: use model_id instead of model model = OpenAIModel(model_id="gpt-4o-mini") agent = CodeAgent( model=model, tools=[] ) result = agent.run("Say hello world in a fun way!") return result except Exception as e: return f"Error: {str(e)}" with gr.Blocks() as demo: gr.Markdown("# 🤖 SmolAgents Hello World Demo") gr.Markdown("Paste your OpenAI API key and press the button.") api_input = gr.Textbox( label="OpenAI API Key", type="password", placeholder="sk-..." ) output = gr.Textbox( label="Agent Output", lines=6 ) run_button = gr.Button("Run Hello World") run_button.click( fn=run_hello_world, inputs=api_input, outputs=output ) if __name__ == "__main__": demo.launch()