cicboy commited on
Commit
aa67901
Β·
1 Parent(s): 90f40ea

update gradio UI

Browse files
Files changed (1) hide show
  1. app.py +37 -19
app.py CHANGED
@@ -26,7 +26,7 @@ hybrid_tool = HybridRetrieverTool(alpha=0.6) #including RAG in search
26
  #Creating Agents
27
 
28
  planner = Agent(
29
- role="Content Planner",
30
  goal="Plan engaging and factually accurate content on {topic}",
31
  backstory="You are working on planning a blog article about the topic {topic}."
32
  "Use the retriever tool to gather accurate, recent information before outlining." #RAG search
@@ -39,10 +39,10 @@ planner = Agent(
39
  )
40
 
41
  writer = Agent(
42
- role="Content Writer",
43
  goal="Write an insightful and factually accurate opinion piece about the topic: {topic}",
44
  backstory="You are working on writing a new opnion piece about the topic: {topic}. "
45
- "You base your writing on the work of the Content Planner, who provides an outline and relevant context about the topic. "
46
  "You follow the main objectives and direction of the outline, as provided by the Content Planner. "
47
  "You also provide objective and impartial insights, supported by relevant information that is provided by the Content Planner. "
48
  "You acknowledge in your opnion piece when your statements are opinions as opposed to objective staements.",
@@ -52,7 +52,7 @@ writer = Agent(
52
  )
53
 
54
  fact_checker = Agent(
55
- role="Fact Checker",
56
  goal="Verify factual accuracy, detect unsupported claims and identify missing references or sources.",
57
  backstory="You are a meticulous research analyst who checks every claim against known facts and relaible sources"
58
  "Use the retriever tool to cross-check the Content Writer's statements against reliable, recent information.",
@@ -63,7 +63,7 @@ fact_checker = Agent(
63
  )
64
 
65
  editor = Agent(
66
- role="Editor",
67
  goal="Edit a given blog post to align with the context and narrative style of the {topic} (e.g. academic, informal, satirical).",
68
  backstory="You are an editor who receives a blog post from the Content Writer. "
69
  "Your goal is to review the blog post to ensure that it follows journalistic best practices, "
@@ -151,19 +151,33 @@ def fetch_context(topic):
151
  return summary
152
 
153
  # Define Gradio Handler
154
- def generate_blog(topic, tone):
155
- yield "⏳ Generating blog β€” this may take a few moments..."
156
- result = crew.kickoff(inputs={"topic": topic, "tone": tone})
157
-
158
- # CrewOutput -> extract text
159
- if hasattr(result, "raw_output"):
160
- final_text = result.raw_output
161
- elif hasattr(result, "final_output"):
162
- final_text = result.final_output
163
- else:
164
- final_text = str(result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
166
- yield final_text
167
 
168
  # Build Gradio Interface
169
  css = """
@@ -217,14 +231,18 @@ with gr.Blocks(css=css) as demo:
217
  value="academic"
218
  )
219
  fetch_btn = gr.Button("🌐 Fetch & Summarize Context", variant="secondary") # Rag Search
220
- context_output = gr.Markdown(label="πŸ“š Retrieved Context Summary") # Rag Search
 
 
 
 
221
 
222
 
223
  run_button = gr.Button("πŸš€ Generate Blog", variant="primary")
224
  output = gr.Textbox(label="πŸ“° Generated Blog Post", elem_id="output-box", lines=25, interactive=False, show_label=False)
225
 
226
  fetch_btn.click(fetch_context, inputs=[topic], outputs=[context_output]) # Rag Search
227
- run_button.click(generate_blog, inputs=[topic, tone], outputs=[output])
228
 
229
  #Launch app
230
  if __name__=="__main__":
 
26
  #Creating Agents
27
 
28
  planner = Agent(
29
+ role="Research Lead",
30
  goal="Plan engaging and factually accurate content on {topic}",
31
  backstory="You are working on planning a blog article about the topic {topic}."
32
  "Use the retriever tool to gather accurate, recent information before outlining." #RAG search
 
39
  )
40
 
41
  writer = Agent(
42
+ role="Technical Writer",
43
  goal="Write an insightful and factually accurate opinion piece about the topic: {topic}",
44
  backstory="You are working on writing a new opnion piece about the topic: {topic}. "
45
+ "You base your writing on the work of the research lead, who provides an outline and relevant context about the topic. "
46
  "You follow the main objectives and direction of the outline, as provided by the Content Planner. "
47
  "You also provide objective and impartial insights, supported by relevant information that is provided by the Content Planner. "
48
  "You acknowledge in your opnion piece when your statements are opinions as opposed to objective staements.",
 
52
  )
53
 
54
  fact_checker = Agent(
55
+ role="Data Verifier",
56
  goal="Verify factual accuracy, detect unsupported claims and identify missing references or sources.",
57
  backstory="You are a meticulous research analyst who checks every claim against known facts and relaible sources"
58
  "Use the retriever tool to cross-check the Content Writer's statements against reliable, recent information.",
 
63
  )
64
 
65
  editor = Agent(
66
+ role="Editor-in-Chief",
67
  goal="Edit a given blog post to align with the context and narrative style of the {topic} (e.g. academic, informal, satirical).",
68
  backstory="You are an editor who receives a blog post from the Content Writer. "
69
  "Your goal is to review the blog post to ensure that it follows journalistic best practices, "
 
151
  return summary
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
+ progress(0, desc="Starting collaborative report generation...")
159
+ yield "🧭 Starting collaborative report generation...\n"
160
+
161
+ # Step 1️⃣ Research Lead
162
+ progress(0.25, desc="Research Lead generating outline...")
163
+ plan_result = crew.tasks[0].run(inputs={"topic": topic, "tone": tone})
164
+ yield f"### 🧠 Research Lead (Outline)\n{plan_result.output_text}\n\n---\n"
165
+
166
+ # Step 2️⃣ Technical Writer
167
+ progress(0.50, desc="Technical Writer drafting content...")
168
+ write_result = crew.tasks[1].run(inputs={"topic": topic, "tone": tone}, context=[plan_result])
169
+ yield f"### ✍️ Technical Writer (Draft)\n{write_result.output_text}\n\n---\n"
170
+
171
+ # Step 3️⃣ Data Verifier
172
+ progress(0.75, desc="Fact-checking underway...")
173
+ fact_result = crew.tasks[2].run(inputs={"topic": topic, "tone": tone}, context=[write_result])
174
+ yield f"### πŸ” Data Verifier (Fact-Checking)\n{fact_result.output_text}\n\n---\n"
175
+
176
+ # Step 4️⃣ Editor-in-Chief
177
+ progress(1.0, desc="Final editing and polish...")
178
+ edit_result = crew.tasks[3].run(inputs={"topic": topic, "tone": tone}, context=[fact_result])
179
+ yield f"### 🧾 Editor-in-Chief (Final Blog)\n{edit_result.output_text}"
180
 
 
181
 
182
  # Build Gradio Interface
183
  css = """
 
231
  value="academic"
232
  )
233
  fetch_btn = gr.Button("🌐 Fetch & Summarize Context", variant="secondary") # Rag Search
234
+ context_output = gr.Markdown(label="πŸ“š Retrieved Context Summary")
235
+ plan_output = gr.Markdown(label="πŸ“˜ Research Outline")
236
+ write_output = gr.Markdown(label="πŸ“ Draft Report")
237
+ fact_output = gr.Markdown(label="πŸ” Fact-Checked Version")
238
+ edit_output = gr.Markdown(label="βœ… Final Blog") # Rag Search
239
 
240
 
241
  run_button = gr.Button("πŸš€ Generate Blog", variant="primary")
242
  output = gr.Textbox(label="πŸ“° Generated Blog Post", elem_id="output-box", lines=25, interactive=False, show_label=False)
243
 
244
  fetch_btn.click(fetch_context, inputs=[topic], outputs=[context_output]) # Rag Search
245
+ run_button.click(generate_blog, inputs=[topic, tone], outputs=[plan_output, write_output, fact_output, edit_output])
246
 
247
  #Launch app
248
  if __name__=="__main__":