Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import streamlit as st
|
|
3 |
from crewai import Agent, Task, Crew
|
4 |
import os
|
5 |
from langchain_groq import ChatGroq
|
6 |
-
from langchain_openai import ChatOpenAI
|
7 |
from fpdf import FPDF
|
8 |
import pandas as pd
|
9 |
import plotly.express as px
|
@@ -25,33 +24,6 @@ st.sidebar.header("User Inputs")
|
|
25 |
patent_area = st.text_input("Enter Patent Technology Area", value="Transparent Antennas for Windshields")
|
26 |
stakeholder = st.text_input("Enter Stakeholder", value="Patent Attorneys")
|
27 |
|
28 |
-
# Initialize LLM
|
29 |
-
llm = None
|
30 |
-
|
31 |
-
# Model Selection
|
32 |
-
#st.header("Model Selection")
|
33 |
-
model_choice = st.radio("Select LLM", ["OpenAI Model", "Groq-based LLM"], index=0, horizontal=True)
|
34 |
-
|
35 |
-
|
36 |
-
# API Key Validation and LLM Initialization
|
37 |
-
groq_api_key = os.getenv("GROQ_API_KEY")
|
38 |
-
openai_api_key = os.getenv("OPENAI_API_KEY")
|
39 |
-
|
40 |
-
#llm = ChatGroq(groq_api_key=os.getenv("GROQ_API_KEY"), model="groq/llama-3.3-70b-versatile")
|
41 |
-
|
42 |
-
if model_choice == "Groq-based LLM":
|
43 |
-
if not groq_api_key:
|
44 |
-
st.error("Groq API key is missing. Please set the GROQ_API_KEY environment variable.")
|
45 |
-
llm = None
|
46 |
-
else:
|
47 |
-
llm = ChatGroq(groq_api_key=groq_api_key, model="groq/llama-3.3-70b-versatile")
|
48 |
-
elif model_choice == "OpenAI Model":
|
49 |
-
if not openai_api_key:
|
50 |
-
st.error("OpenAI API key is missing. Please set the OPENAI_API_KEY environment variable.")
|
51 |
-
llm = None
|
52 |
-
else:
|
53 |
-
llm = ChatOpenAI(api_key=openai_api_key, model="gpt-4o")
|
54 |
-
|
55 |
# Advanced Options
|
56 |
st.sidebar.header("Advanced Options")
|
57 |
enable_advanced_analysis = st.sidebar.checkbox("Enable Advanced Analysis", value=True)
|
@@ -79,6 +51,8 @@ with st.sidebar.expander("Customize Agent Goals", expanded=False):
|
|
79 |
writer_goal = "Craft a professional insights document summarizing trends, strategies, and actionable outcomes for stakeholders."
|
80 |
analyst_goal = "Perform detailed statistical analysis of patent filings, growth trends, and innovation distribution."
|
81 |
|
|
|
|
|
82 |
|
83 |
# Agent Definitions
|
84 |
planner = Agent(
|
@@ -133,7 +107,7 @@ write = Task(
|
|
133 |
"2. Include key findings, visual aids, and actionable strategies.\n"
|
134 |
"3. Suggest strategic directions and highlight untapped innovation areas.\n"
|
135 |
"4. Incorporate summarized tables for key statistics and example inventions.\n"
|
136 |
-
"5. Limit the document to
|
137 |
),
|
138 |
expected_output="A polished, stakeholder-ready patent insights document with actionable recommendations.",
|
139 |
agent=writer
|
@@ -259,51 +233,42 @@ def display_table(analyst_output):
|
|
259 |
return table_data
|
260 |
|
261 |
# Main Execution Block
|
262 |
-
if st.button("Generate Insights"):
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
writer_output
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
with
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
table_data=table_data,
|
302 |
-
metadata={"Technology Area": patent_area, "Stakeholder": stakeholder}
|
303 |
-
)
|
304 |
-
with open(pdf_path, "rb") as report_file:
|
305 |
-
st.download_button("Download Report", data=report_file, file_name="Patent_Strategy_Report.pdf")
|
306 |
-
|
307 |
-
except Exception as e:
|
308 |
-
logging.error(f"An error occurred during execution: {e}")
|
309 |
-
st.error(f"An error occurred during execution: {e}")
|
|
|
3 |
from crewai import Agent, Task, Crew
|
4 |
import os
|
5 |
from langchain_groq import ChatGroq
|
|
|
6 |
from fpdf import FPDF
|
7 |
import pandas as pd
|
8 |
import plotly.express as px
|
|
|
24 |
patent_area = st.text_input("Enter Patent Technology Area", value="Transparent Antennas for Windshields")
|
25 |
stakeholder = st.text_input("Enter Stakeholder", value="Patent Attorneys")
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# Advanced Options
|
28 |
st.sidebar.header("Advanced Options")
|
29 |
enable_advanced_analysis = st.sidebar.checkbox("Enable Advanced Analysis", value=True)
|
|
|
51 |
writer_goal = "Craft a professional insights document summarizing trends, strategies, and actionable outcomes for stakeholders."
|
52 |
analyst_goal = "Perform detailed statistical analysis of patent filings, growth trends, and innovation distribution."
|
53 |
|
54 |
+
# LLM Initialization
|
55 |
+
llm = ChatGroq(groq_api_key=os.getenv("GROQ_API_KEY"), model="groq/llama-3.3-70b-versatile")
|
56 |
|
57 |
# Agent Definitions
|
58 |
planner = Agent(
|
|
|
107 |
"2. Include key findings, visual aids, and actionable strategies.\n"
|
108 |
"3. Suggest strategic directions and highlight untapped innovation areas.\n"
|
109 |
"4. Incorporate summarized tables for key statistics and example inventions.\n"
|
110 |
+
"5. Limit the document to 600 words."
|
111 |
),
|
112 |
expected_output="A polished, stakeholder-ready patent insights document with actionable recommendations.",
|
113 |
agent=writer
|
|
|
233 |
return table_data
|
234 |
|
235 |
# Main Execution Block
|
236 |
+
if st.button("Generate Patent Insights"):
|
237 |
+
with st.spinner('Processing...'):
|
238 |
+
try:
|
239 |
+
start_time = time.time()
|
240 |
+
results = crew.kickoff(inputs={"topic": patent_area, "stakeholder": stakeholder})
|
241 |
+
elapsed_time = time.time() - start_time
|
242 |
+
|
243 |
+
writer_output = getattr(results.tasks_output[2], "raw", "No details available.")
|
244 |
+
if writer_output:
|
245 |
+
st.markdown("### Final Report")
|
246 |
+
st.write(writer_output)
|
247 |
+
else:
|
248 |
+
st.warning("No final report available.")
|
249 |
+
|
250 |
+
with st.expander("Explore Detailed Insights"):
|
251 |
+
tab1, tab2 = st.tabs(["Planner's Insights", "Analyst's Analysis"])
|
252 |
+
|
253 |
+
with tab1:
|
254 |
+
planner_output = getattr(results.tasks_output[0], "raw", "No details available.")
|
255 |
+
st.write(planner_output)
|
256 |
+
|
257 |
+
with tab2:
|
258 |
+
analyst_output = getattr(results.tasks_output[1], "raw", "No details available.")
|
259 |
+
st.write(analyst_output)
|
260 |
+
|
261 |
+
charts = []
|
262 |
+
if enable_advanced_analysis:
|
263 |
+
charts = create_visualizations(analyst_output)
|
264 |
+
|
265 |
+
table_data = display_table(analyst_output)
|
266 |
+
|
267 |
+
st.success(f"Analysis completed in {elapsed_time:.2f} seconds.")
|
268 |
+
pdf_path = generate_pdf_report(writer_output, charts=charts, table_data=table_data, metadata={"Technology Area": patent_area, "Stakeholder": stakeholder})
|
269 |
+
with open(pdf_path, "rb") as report_file:
|
270 |
+
st.download_button("Download Report", data=report_file, file_name="Patent_Strategy_Report.pdf")
|
271 |
+
|
272 |
+
except Exception as e:
|
273 |
+
logging.error(f"An error occurred during execution: {e}")
|
274 |
+
st.error(f"An error occurred during execution: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|