dindizz commited on
Commit
23d5121
·
verified ·
1 Parent(s): 355f509

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from openai import OpenAI
4
+
5
+ # Initialize OpenAI client
6
+ openai = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
7
+
8
+ # Function to fetch positive news using the Responses API
9
+ def fetch_positive_news():
10
+ response = openai.responses.create(
11
+ model="gpt-4o",
12
+ input="What was a positive news story that happened today?",
13
+ tools=[{"type": "web_search"}]
14
+ )
15
+ return response.output_text
16
+
17
+ # Gradio Interface
18
+ demo = gr.Interface(
19
+ fn=fetch_positive_news,
20
+ inputs=None,
21
+ outputs="text",
22
+ title="Daily Positive News",
23
+ description="Click the button to fetch a positive news story from today using OpenAI's Responses API.",
24
+ allow_flagging="never"
25
+ )
26
+
27
+ # Launch the Gradio app
28
+ demo.launch()