File size: 1,139 Bytes
51705d6
 
 
 
 
 
 
 
 
 
 
 
 
be3e20e
 
 
51705d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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()