Afeezee commited on
Commit
37dff90
·
verified ·
1 Parent(s): a2d8d63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -83,17 +83,20 @@ def analyze_document(file):
83
  """Processes and analyzes the uploaded document."""
84
  text = extract_text_from_file(file)
85
  if text.startswith("Unsupported file format"):
86
- return text
 
87
 
88
  chunks = chunk_text(text)
89
  all_insights = []
90
 
91
- for chunk in chunks:
 
 
92
  result = analyze_chunk(chunk)
93
  if result.strip(): # Only append non-empty results
94
  all_insights.append(result)
95
 
96
- # Consolidate all results into a single final summary
97
  consolidated_summary_prompt = (
98
  "Below are insights extracted from multiple chunks of a document. "
99
  "Consolidate these insights into a single output organized as follows: "
@@ -112,7 +115,7 @@ def analyze_document(file):
112
  stream=False
113
  )
114
 
115
- return final_summary.choices[0].message.content
116
 
117
  # Define the Gradio interface
118
  interface = gr.Interface(
@@ -128,4 +131,4 @@ interface = gr.Interface(
128
 
129
  # Launch the interface
130
  if __name__ == "__main__":
131
- interface.launch()
 
83
  """Processes and analyzes the uploaded document."""
84
  text = extract_text_from_file(file)
85
  if text.startswith("Unsupported file format"):
86
+ yield f"**Error:** {text}"
87
+ return
88
 
89
  chunks = chunk_text(text)
90
  all_insights = []
91
 
92
+ yield "**Processing the document. Please wait...**\n"
93
+ for i, chunk in enumerate(chunks, 1):
94
+ yield f"**Processing chunk {i} of {len(chunks)}...**"
95
  result = analyze_chunk(chunk)
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. "
102
  "Consolidate these insights into a single output organized as follows: "
 
115
  stream=False
116
  )
117
 
118
+ yield f"**Final Summary:**\n\n{final_summary.choices[0].message.content}"
119
 
120
  # Define the Gradio interface
121
  interface = gr.Interface(
 
131
 
132
  # Launch the interface
133
  if __name__ == "__main__":
134
+ interface.launch()