Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -96,6 +96,10 @@ def analyze_document(file):
|
|
96 |
if result.strip(): # Only append non-empty results
|
97 |
all_insights.append(result)
|
98 |
|
|
|
|
|
|
|
|
|
99 |
yield "**Consolidating all insights into a final summary...**"
|
100 |
consolidated_summary_prompt = (
|
101 |
"Below are insights extracted from multiple chunks of a document. "
|
@@ -103,19 +107,22 @@ def analyze_document(file):
|
|
103 |
"Author, Year, Title; Problem addressed; Methodology; Results; and Remarks. "
|
104 |
"Make the final output concise and coherent."
|
105 |
)
|
106 |
-
final_summary = client.chat.completions.create(
|
107 |
-
model="llama-3.3-70b-versatile",
|
108 |
-
messages=[
|
109 |
-
{"role": "system", "content": consolidated_summary_prompt},
|
110 |
-
{"role": "user", "content": "\n\n".join(all_insights)}
|
111 |
-
],
|
112 |
-
temperature=0.7,
|
113 |
-
max_tokens=4096,
|
114 |
-
top_p=1,
|
115 |
-
stream=False
|
116 |
-
)
|
117 |
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
# Define the Gradio interface
|
121 |
interface = gr.Interface(
|
@@ -131,4 +138,4 @@ interface = gr.Interface(
|
|
131 |
|
132 |
# Launch the interface
|
133 |
if __name__ == "__main__":
|
134 |
-
interface.launch()
|
|
|
96 |
if result.strip(): # Only append non-empty results
|
97 |
all_insights.append(result)
|
98 |
|
99 |
+
if not all_insights:
|
100 |
+
yield "**Error:** No valid insights were extracted from the document."
|
101 |
+
return
|
102 |
+
|
103 |
yield "**Consolidating all insights into a final summary...**"
|
104 |
consolidated_summary_prompt = (
|
105 |
"Below are insights extracted from multiple chunks of a document. "
|
|
|
107 |
"Author, Year, Title; Problem addressed; Methodology; Results; and Remarks. "
|
108 |
"Make the final output concise and coherent."
|
109 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
+
try:
|
112 |
+
final_summary = client.chat.completions.create(
|
113 |
+
model="llama-3.3-70b-versatile",
|
114 |
+
messages=[
|
115 |
+
{"role": "system", "content": consolidated_summary_prompt},
|
116 |
+
{"role": "user", "content": "\n\n".join(all_insights)}
|
117 |
+
],
|
118 |
+
temperature=0.7,
|
119 |
+
max_tokens=4096,
|
120 |
+
top_p=1,
|
121 |
+
stream=False
|
122 |
+
)
|
123 |
+
yield f"**Final Summary:**\n\n{final_summary.choices[0].message.content}"
|
124 |
+
except Exception as e:
|
125 |
+
yield f"**Error:** An error occurred during consolidation: {e}"
|
126 |
|
127 |
# Define the Gradio interface
|
128 |
interface = gr.Interface(
|
|
|
138 |
|
139 |
# Launch the interface
|
140 |
if __name__ == "__main__":
|
141 |
+
interface.launch()
|