DrishtiSharma commited on
Commit
65c3595
·
verified ·
1 Parent(s): 3630283

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -77
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 650 words."
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
- if llm is None:
264
- st.error("Cannot proceed without a valid API key for the selected model.")
265
- else:
266
- with st.spinner('Processing...'):
267
- try:
268
- start_time = time.time()
269
- results = crew.kickoff(inputs={"topic": patent_area, "stakeholder": stakeholder})
270
- elapsed_time = time.time() - start_time
271
-
272
- writer_output = getattr(results.tasks_output[2], "raw", "No details available.")
273
- if writer_output:
274
- st.markdown("### Final Report")
275
- st.write(writer_output)
276
- else:
277
- st.warning("No final report available.")
278
-
279
- with st.expander("Explore Detailed Insights"):
280
- tab1, tab2 = st.tabs(["Planner's Insights", "Analyst's Analysis"])
281
-
282
- with tab1:
283
- planner_output = getattr(results.tasks_output[0], "raw", "No details available.")
284
- st.write(planner_output)
285
-
286
- with tab2:
287
- analyst_output = getattr(results.tasks_output[1], "raw", "No details available.")
288
- st.subheader("Raw Analyst Output")
289
- st.write(analyst_output)
290
-
291
- charts = []
292
- if enable_advanced_analysis:
293
- charts = create_visualizations(analyst_output)
294
-
295
- table_data = display_table(analyst_output)
296
-
297
- st.success(f"Analysis completed in {elapsed_time:.2f} seconds.")
298
- pdf_path = generate_pdf_report(
299
- writer_output,
300
- charts=charts,
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}")