Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,27 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
def fetch_positive_news():
|
| 8 |
-
response =
|
| 9 |
model="gpt-4o",
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
)
|
| 13 |
-
return response.
|
| 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
|
| 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 |
|