dindizz commited on
Commit
2cdae63
·
verified ·
1 Parent(s): ae7e6cc

Update app.py

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