Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,6 +32,9 @@ elif model_choice == "OpenAI":
|
|
32 |
else:
|
33 |
llm = ChatOpenAI(api_key=openai_api_key, model="gpt-4o")
|
34 |
|
|
|
|
|
|
|
35 |
|
36 |
# Title and Application Introduction
|
37 |
st.title("Patent Strategy and Innovation Consultant")
|
@@ -252,41 +255,49 @@ def display_table(analyst_output):
|
|
252 |
|
253 |
# Main Execution Block
|
254 |
if st.button("Generate Insights"):
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
with
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
st.
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
else:
|
33 |
llm = ChatOpenAI(api_key=openai_api_key, model="gpt-4o")
|
34 |
|
35 |
+
# Model Selection on Main Screen
|
36 |
+
st.header("Model Selection")
|
37 |
+
model_choice = st.selectbox("Select LLM Provider", ["Groq-based LLM", "OpenAI"])
|
38 |
|
39 |
# Title and Application Introduction
|
40 |
st.title("Patent Strategy and Innovation Consultant")
|
|
|
255 |
|
256 |
# Main Execution Block
|
257 |
if st.button("Generate Insights"):
|
258 |
+
if llm is None:
|
259 |
+
st.error("Cannot proceed without a valid API key for the selected model.")
|
260 |
+
else:
|
261 |
+
with st.spinner('Processing...'):
|
262 |
+
try:
|
263 |
+
start_time = time.time()
|
264 |
+
results = crew.kickoff(inputs={"topic": patent_area, "stakeholder": stakeholder})
|
265 |
+
elapsed_time = time.time() - start_time
|
266 |
+
|
267 |
+
writer_output = getattr(results.tasks_output[2], "raw", "No details available.")
|
268 |
+
if writer_output:
|
269 |
+
st.markdown("### Final Report")
|
270 |
+
st.write(writer_output)
|
271 |
+
else:
|
272 |
+
st.warning("No final report available.")
|
273 |
+
|
274 |
+
with st.expander("Explore Detailed Insights"):
|
275 |
+
tab1, tab2 = st.tabs(["Planner's Insights", "Analyst's Analysis"])
|
276 |
+
|
277 |
+
with tab1:
|
278 |
+
planner_output = getattr(results.tasks_output[0], "raw", "No details available.")
|
279 |
+
st.write(planner_output)
|
280 |
+
|
281 |
+
with tab2:
|
282 |
+
analyst_output = getattr(results.tasks_output[1], "raw", "No details available.")
|
283 |
+
st.write(analyst_output)
|
284 |
+
|
285 |
+
charts = []
|
286 |
+
if enable_advanced_analysis:
|
287 |
+
charts = create_visualizations(analyst_output)
|
288 |
+
|
289 |
+
table_data = display_table(analyst_output)
|
290 |
+
|
291 |
+
st.success(f"Analysis completed in {elapsed_time:.2f} seconds.")
|
292 |
+
pdf_path = generate_pdf_report(
|
293 |
+
writer_output,
|
294 |
+
charts=charts,
|
295 |
+
table_data=table_data,
|
296 |
+
metadata={"Technology Area": patent_area, "Stakeholder": stakeholder}
|
297 |
+
)
|
298 |
+
with open(pdf_path, "rb") as report_file:
|
299 |
+
st.download_button("Download Report", data=report_file, file_name="Patent_Strategy_Report.pdf")
|
300 |
+
|
301 |
+
except Exception as e:
|
302 |
+
logging.error(f"An error occurred during execution: {e}")
|
303 |
+
st.error(f"An error occurred during execution: {e}")
|