Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from duckduckgo_search import DDGS
|
3 |
from datetime import datetime
|
4 |
import os
|
|
|
5 |
from openai import OpenAI # Using standard OpenAI client
|
6 |
from agents import Agent, Runner, function_tool # Assuming agents package is installed
|
7 |
|
@@ -94,21 +95,30 @@ editor_agent = Agent(
|
|
94 |
|
95 |
# Workflow function for Gradio
|
96 |
def fetch_and_edit_news(topic, language, search_date):
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
# Create Gradio interface
|
114 |
with gr.Blocks(title="Multilingual AI News Generator") as demo:
|
@@ -144,4 +154,4 @@ with gr.Blocks(title="Multilingual AI News Generator") as demo:
|
|
144 |
|
145 |
# Launch the app
|
146 |
if __name__ == "__main__":
|
147 |
-
demo.launch()
|
|
|
2 |
from duckduckgo_search import DDGS
|
3 |
from datetime import datetime
|
4 |
import os
|
5 |
+
import asyncio
|
6 |
from openai import OpenAI # Using standard OpenAI client
|
7 |
from agents import Agent, Runner, function_tool # Assuming agents package is installed
|
8 |
|
|
|
95 |
|
96 |
# Workflow function for Gradio
|
97 |
def fetch_and_edit_news(topic, language, search_date):
|
98 |
+
try:
|
99 |
+
# Create a new event loop for this thread
|
100 |
+
loop = asyncio.new_event_loop()
|
101 |
+
asyncio.set_event_loop(loop)
|
102 |
+
|
103 |
+
# Step 1: Run the news agent
|
104 |
+
news_result = Runner.run_sync(
|
105 |
+
news_agent,
|
106 |
+
f"Get me the news about {topic} in {language} for date {search_date}")
|
107 |
+
|
108 |
+
raw_news = news_result.final_output
|
109 |
+
|
110 |
+
# Step 2: Pass news to editor for final review
|
111 |
+
editor_news_response = Runner.run_sync(
|
112 |
+
editor_agent,
|
113 |
+
f"Please edit the following news in {language} language. Maintain the original language: \n\n{raw_news}")
|
114 |
+
|
115 |
+
edited_news = editor_news_response.final_output
|
116 |
+
|
117 |
+
return edited_news
|
118 |
+
|
119 |
+
except Exception as e:
|
120 |
+
# Return the error message for debugging
|
121 |
+
return f"Error: {str(e)}\n\nThis could be due to API key issues or problems with the openai-agents package. Please check the logs for more details."
|
122 |
|
123 |
# Create Gradio interface
|
124 |
with gr.Blocks(title="Multilingual AI News Generator") as demo:
|
|
|
154 |
|
155 |
# Launch the app
|
156 |
if __name__ == "__main__":
|
157 |
+
demo.launch()
|