Spaces:
Sleeping
Sleeping
update gradio UI
Browse files
app.py
CHANGED
|
@@ -152,35 +152,24 @@ def fetch_context(topic):
|
|
| 152 |
|
| 153 |
# Define Gradio Handler
|
| 154 |
import time
|
| 155 |
-
|
| 156 |
-
|
| 157 |
def generate_blog(topic, tone, progress=gr.Progress(track_tqdm=True)):
|
| 158 |
-
# initialize progress bar
|
| 159 |
progress(0, desc="Starting collaborative report generation...")
|
| 160 |
yield "### 🧭 Starting Collaborative Report\n"
|
| 161 |
|
| 162 |
-
#
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
progress(0.75, desc="Fact-checking underway...")
|
| 176 |
-
fact_result = crew.tasks[2].run(inputs={"topic": topic, "tone": tone}, context=[write_result])
|
| 177 |
-
yield f"### 🔍 Data Verifier (Fact-Checking)\n{fact_result.output_text}\n\n---\n"
|
| 178 |
-
time.sleep(0.3)
|
| 179 |
-
|
| 180 |
-
# Step 4️⃣ Editor-in-Chief
|
| 181 |
-
progress(1.0, desc="Final editing and polish...")
|
| 182 |
-
edit_result = crew.tasks[3].run(inputs={"topic": topic, "tone": tone}, context=[fact_result])
|
| 183 |
-
yield f"### 🧾 Editor-in-Chief (Final Blog)\n{edit_result.output_text}\n\n✅ **Report Complete!**"
|
| 184 |
|
| 185 |
# Build Gradio Interface
|
| 186 |
css = """
|
|
@@ -237,7 +226,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 237 |
context_output = gr.Markdown(label="📚 Retrieved Context Summary") # Rag Search
|
| 238 |
|
| 239 |
run_button = gr.Button("🚀 Generate Blog", variant="primary")
|
| 240 |
-
final_output = gr.Textbox(label="📰 Generated Blog Post", elem_id="output-box")
|
| 241 |
|
| 242 |
fetch_btn.click(fetch_context, inputs=[topic], outputs=[context_output]) # Rag Search
|
| 243 |
run_button.click(generate_blog, inputs=[topic, tone], outputs=[final_output])
|
|
|
|
| 152 |
|
| 153 |
# Define Gradio Handler
|
| 154 |
import time
|
| 155 |
+
from datetime import datetime
|
|
|
|
| 156 |
def generate_blog(topic, tone, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
| 157 |
progress(0, desc="Starting collaborative report generation...")
|
| 158 |
yield "### 🧭 Starting Collaborative Report\n"
|
| 159 |
|
| 160 |
+
# Run the entire crew sequentially and stream outputs
|
| 161 |
+
stream = crew.kickoff_stream(inputs={"topic": topic, "tone": tone})
|
| 162 |
+
|
| 163 |
+
# Stream each agent’s output as it arrives
|
| 164 |
+
for event in stream:
|
| 165 |
+
role = event.get("agent", "Agent")
|
| 166 |
+
output = event.get("output", "")
|
| 167 |
+
if output:
|
| 168 |
+
timestamp = datetime.now().strftime("[%H:%M:S]")
|
| 169 |
+
yield f"{timestamp} 🧩 **{role}**\n{output}\n\n---\n"
|
| 170 |
+
|
| 171 |
+
progress(1.0, desc="Finalizing report...")
|
| 172 |
+
yield "✅ **All agents have completed their work! Final blog generated.**"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
# Build Gradio Interface
|
| 175 |
css = """
|
|
|
|
| 226 |
context_output = gr.Markdown(label="📚 Retrieved Context Summary") # Rag Search
|
| 227 |
|
| 228 |
run_button = gr.Button("🚀 Generate Blog", variant="primary")
|
| 229 |
+
final_output = gr.Textbox(label="📰 Generated Blog Post", elem_id="output-box", lines=30, interactive=False, show_label=True)
|
| 230 |
|
| 231 |
fetch_btn.click(fetch_context, inputs=[topic], outputs=[context_output]) # Rag Search
|
| 232 |
run_button.click(generate_blog, inputs=[topic, tone], outputs=[final_output])
|