Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,8 @@
|
|
| 1 |
import os
|
| 2 |
import textwrap
|
| 3 |
|
| 4 |
-
# βββ CrewAI core βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 5 |
from crewai import Agent, Task, Crew, Process, LLM
|
| 6 |
from crewai_tools import SerperDevTool, ScrapeWebsiteTool
|
| 7 |
-
|
| 8 |
-
# βββ UI ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 9 |
import gradio as gr
|
| 10 |
|
| 11 |
# =============================================================================
|
|
@@ -19,17 +16,16 @@ SERPER_API_KEY = os.environ.get("SERPER_API_KEY", "")
|
|
| 19 |
|
| 20 |
if not OPENAI_API_KEY:
|
| 21 |
raise EnvironmentError(
|
| 22 |
-
"
|
| 23 |
-
"Add it in Space
|
| 24 |
)
|
| 25 |
|
| 26 |
if not SERPER_API_KEY:
|
| 27 |
raise EnvironmentError(
|
| 28 |
-
"
|
| 29 |
-
"Add it in Space
|
| 30 |
)
|
| 31 |
|
| 32 |
-
# CrewAI and LangChain pick these up automatically from os.environ
|
| 33 |
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
|
| 34 |
os.environ["SERPER_API_KEY"] = SERPER_API_KEY
|
| 35 |
|
|
@@ -78,7 +74,7 @@ researcher = Agent(
|
|
| 78 |
"You never make assumptions β everything you report is evidence-backed. "
|
| 79 |
"You organize research into clean bullet points with source context."
|
| 80 |
),
|
| 81 |
-
tools=[search_tool, scrape_tool],
|
| 82 |
llm=llm,
|
| 83 |
verbose=True,
|
| 84 |
allow_delegation=False,
|
|
@@ -260,21 +256,15 @@ def run_crew(topic: str, audience: str, tone: str, length: str) -> str:
|
|
| 260 |
return error_msg
|
| 261 |
|
| 262 |
# =============================================================================
|
| 263 |
-
# GRADIO UI
|
|
|
|
|
|
|
| 264 |
# =============================================================================
|
| 265 |
-
with gr.Blocks(
|
| 266 |
-
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="slate"),
|
| 267 |
-
title="Multi-Agent Article Generator",
|
| 268 |
-
css="""
|
| 269 |
-
.title-text { text-align: center; }
|
| 270 |
-
.agent-badge { font-size: 0.85rem; color: #666; }
|
| 271 |
-
footer { display: none !important; }
|
| 272 |
-
"""
|
| 273 |
-
) as demo:
|
| 274 |
|
| 275 |
gr.Markdown(
|
| 276 |
"""
|
| 277 |
-
<div
|
| 278 |
<h1>Multi-Agent Article Generator</h1>
|
| 279 |
<p style="color:#555;">Powered by <strong>CrewAI</strong> + <strong>GPT-4o</strong> + <strong>SerperDev</strong> + <strong>ScrapeWebsite</strong></p>
|
| 280 |
</div>
|
|
@@ -354,7 +344,7 @@ with gr.Blocks(
|
|
| 354 |
|
| 355 |
gr.Markdown(
|
| 356 |
"""
|
| 357 |
-
<div
|
| 358 |
<b>Agents:</b><br>
|
| 359 |
Researcher - web search + scrape full pages<br>
|
| 360 |
Writer - draft structured article<br>
|
|
@@ -374,7 +364,6 @@ with gr.Blocks(
|
|
| 374 |
"This takes 45-120 seconds.\n"
|
| 375 |
"Watch the Space logs for live agent output."
|
| 376 |
),
|
| 377 |
-
show_copy_button=True,
|
| 378 |
interactive=False,
|
| 379 |
)
|
| 380 |
|
|
@@ -417,5 +406,9 @@ with gr.Blocks(
|
|
| 417 |
# LAUNCH
|
| 418 |
# server_name="0.0.0.0" is required for Hugging Face Spaces
|
| 419 |
# server_port=7860 is the default port HF Spaces expects
|
|
|
|
| 420 |
# =============================================================================
|
| 421 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import textwrap
|
| 3 |
|
|
|
|
| 4 |
from crewai import Agent, Task, Crew, Process, LLM
|
| 5 |
from crewai_tools import SerperDevTool, ScrapeWebsiteTool
|
|
|
|
|
|
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
# =============================================================================
|
|
|
|
| 16 |
|
| 17 |
if not OPENAI_API_KEY:
|
| 18 |
raise EnvironmentError(
|
| 19 |
+
"OPENAI_API_KEY not found. "
|
| 20 |
+
"Add it in Space -> Settings -> Variables and secrets."
|
| 21 |
)
|
| 22 |
|
| 23 |
if not SERPER_API_KEY:
|
| 24 |
raise EnvironmentError(
|
| 25 |
+
"SERPER_API_KEY not found. "
|
| 26 |
+
"Add it in Space -> Settings -> Variables and secrets."
|
| 27 |
)
|
| 28 |
|
|
|
|
| 29 |
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
|
| 30 |
os.environ["SERPER_API_KEY"] = SERPER_API_KEY
|
| 31 |
|
|
|
|
| 74 |
"You never make assumptions β everything you report is evidence-backed. "
|
| 75 |
"You organize research into clean bullet points with source context."
|
| 76 |
),
|
| 77 |
+
tools=[search_tool, scrape_tool],
|
| 78 |
llm=llm,
|
| 79 |
verbose=True,
|
| 80 |
allow_delegation=False,
|
|
|
|
| 256 |
return error_msg
|
| 257 |
|
| 258 |
# =============================================================================
|
| 259 |
+
# GRADIO UI β compatible with Gradio 6.x
|
| 260 |
+
# theme and css are passed to launch(), not Blocks()
|
| 261 |
+
# show_copy_button removed (not available in Gradio 6)
|
| 262 |
# =============================================================================
|
| 263 |
+
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
gr.Markdown(
|
| 266 |
"""
|
| 267 |
+
<div style="text-align:center;">
|
| 268 |
<h1>Multi-Agent Article Generator</h1>
|
| 269 |
<p style="color:#555;">Powered by <strong>CrewAI</strong> + <strong>GPT-4o</strong> + <strong>SerperDev</strong> + <strong>ScrapeWebsite</strong></p>
|
| 270 |
</div>
|
|
|
|
| 344 |
|
| 345 |
gr.Markdown(
|
| 346 |
"""
|
| 347 |
+
<div style="font-size:0.85rem; color:#666;">
|
| 348 |
<b>Agents:</b><br>
|
| 349 |
Researcher - web search + scrape full pages<br>
|
| 350 |
Writer - draft structured article<br>
|
|
|
|
| 364 |
"This takes 45-120 seconds.\n"
|
| 365 |
"Watch the Space logs for live agent output."
|
| 366 |
),
|
|
|
|
| 367 |
interactive=False,
|
| 368 |
)
|
| 369 |
|
|
|
|
| 406 |
# LAUNCH
|
| 407 |
# server_name="0.0.0.0" is required for Hugging Face Spaces
|
| 408 |
# server_port=7860 is the default port HF Spaces expects
|
| 409 |
+
# theme and css are passed here in Gradio 6.x
|
| 410 |
# =============================================================================
|
| 411 |
+
demo.launch(
|
| 412 |
+
server_name="0.0.0.0",
|
| 413 |
+
server_port=7860,
|
| 414 |
+
)
|