cicboy commited on
Commit
6aedb51
·
1 Parent(s): 79132ac

update gradio UI

Browse files
Files changed (1) hide show
  1. app.py +15 -26
app.py CHANGED
@@ -152,35 +152,24 @@ def fetch_context(topic):
152
 
153
  # Define Gradio Handler
154
  import time
155
- import gradio as gr
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
- # Step 1️⃣ Research Lead
163
- progress(0.25, desc="Research Lead generating outline...")
164
- plan_result = crew.tasks[0].run(inputs={"topic": topic, "tone": tone})
165
- yield f"### 🧠 Research Lead (Outline)\n{plan_result.output_text}\n\n---\n"
166
- time.sleep(0.3)
167
-
168
- # Step 2️⃣ Technical Writer
169
- progress(0.50, desc="Technical Writer drafting content...")
170
- write_result = crew.tasks[1].run(inputs={"topic": topic, "tone": tone}, context=[plan_result])
171
- yield f"### ✍️ Technical Writer (Draft)\n{write_result.output_text}\n\n---\n"
172
- time.sleep(0.3)
173
-
174
- # Step 3️⃣ Data Verifier
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])