eaglelandsonce commited on
Commit
51705d6
·
verified ·
1 Parent(s): 8935e74

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from smolagents import CodeAgent
4
+ from smolagents.models import OpenAIModel
5
+
6
+
7
+ def run_hello_world(api_key):
8
+ if not api_key:
9
+ return "Please enter your OpenAI API key."
10
+
11
+ # Set environment variable dynamically
12
+ os.environ["OPENAI_API_KEY"] = api_key
13
+
14
+ try:
15
+ # Create model + agent
16
+ model = OpenAIModel(model="gpt-4o-mini")
17
+ agent = CodeAgent(
18
+ model=model,
19
+ tools=[]
20
+ )
21
+
22
+ # Run hello world task
23
+ result = agent.run("Say hello world in a fun way!")
24
+ return result
25
+
26
+ except Exception as e:
27
+ return f"Error: {str(e)}"
28
+
29
+
30
+ # Gradio UI
31
+ with gr.Blocks() as demo:
32
+ gr.Markdown("# 🤖 SmolAgents Hello World Demo")
33
+ gr.Markdown("Paste your OpenAI API key and press the button.")
34
+
35
+ api_input = gr.Textbox(
36
+ label="OpenAI API Key",
37
+ type="password",
38
+ placeholder="sk-..."
39
+ )
40
+
41
+ output = gr.Textbox(
42
+ label="Agent Output",
43
+ lines=6
44
+ )
45
+
46
+ run_button = gr.Button("Run Hello World")
47
+
48
+ run_button.click(
49
+ fn=run_hello_world,
50
+ inputs=api_input,
51
+ outputs=output
52
+ )
53
+
54
+
55
+ if __name__ == "__main__":
56
+ demo.launch()