Update app.py
Browse files
app.py
CHANGED
@@ -126,23 +126,130 @@ def analyze_document(api_key, user_prompt, uploaded_file):
|
|
126 |
)
|
127 |
|
128 |
result = response.choices[0].message.content
|
129 |
-
extracted_texts.append(f"
|
130 |
-
all_results.append(f"π Page {idx}
|
131 |
|
132 |
except Exception as e:
|
133 |
raise gr.Error(f"Error analyzing page {idx}: {e}")
|
134 |
|
135 |
# Generate summary if multiple pages
|
136 |
-
|
137 |
|
138 |
if len(extracted_texts) > 1:
|
139 |
summary = generate_summary("\n".join(extracted_texts), api_key)
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
# --- GRADIO INTERFACE ---
|
145 |
-
with gr.Blocks(
|
|
|
|
|
|
|
|
|
146 |
gr.Markdown("# π§Ύ DocSum")
|
147 |
gr.Markdown("Document Summarizer Powered by VLM β’ Developed by [Koshur AI](https://koshurai.com)")
|
148 |
|
@@ -165,7 +272,7 @@ with gr.Blocks(title="DocSum - Document Summarizer", theme=gr.themes.Soft()) as
|
|
165 |
|
166 |
submit_btn = gr.Button("π Analyze Document", variant="primary")
|
167 |
|
168 |
-
#
|
169 |
output = gr.Markdown(
|
170 |
label="Analysis Results",
|
171 |
elem_classes=["markdown-output"]
|
@@ -177,27 +284,5 @@ with gr.Blocks(title="DocSum - Document Summarizer", theme=gr.themes.Soft()) as
|
|
177 |
outputs=output
|
178 |
)
|
179 |
|
180 |
-
# Add custom CSS for the markdown output
|
181 |
-
css = """
|
182 |
-
.markdown-output {
|
183 |
-
padding: 20px;
|
184 |
-
border-radius: 8px;
|
185 |
-
background: #f9fafb;
|
186 |
-
border: 1px solid #e5e7eb;
|
187 |
-
max-height: 600px;
|
188 |
-
overflow-y: auto;
|
189 |
-
}
|
190 |
-
.markdown-output h2 {
|
191 |
-
color: #2563eb;
|
192 |
-
margin-top: 1.5em;
|
193 |
-
margin-bottom: 0.5em;
|
194 |
-
}
|
195 |
-
.markdown-output h3 {
|
196 |
-
color: #3b82f6;
|
197 |
-
margin-top: 1em;
|
198 |
-
}
|
199 |
-
"""
|
200 |
-
demo.css = css
|
201 |
-
|
202 |
if __name__ == "__main__":
|
203 |
demo.launch()
|
|
|
126 |
)
|
127 |
|
128 |
result = response.choices[0].message.content
|
129 |
+
extracted_texts.append(f"### Page {idx}\n{result}\n")
|
130 |
+
all_results.append(f"## π Page {idx} Results\n{result}\n---\n")
|
131 |
|
132 |
except Exception as e:
|
133 |
raise gr.Error(f"Error analyzing page {idx}: {e}")
|
134 |
|
135 |
# Generate summary if multiple pages
|
136 |
+
markdown_output = "\n".join(all_results)
|
137 |
|
138 |
if len(extracted_texts) > 1:
|
139 |
summary = generate_summary("\n".join(extracted_texts), api_key)
|
140 |
+
markdown_output += f"\n## π Comprehensive Summary\n{summary}\n"
|
141 |
+
|
142 |
+
# Add structured data section
|
143 |
+
markdown_output += f"\n## π Key Data Extracted\n"
|
144 |
+
markdown_output += "- **Important Figures**: [Extracted values]\n"
|
145 |
+
markdown_output += "- **Critical Dates**: [Extracted dates]\n"
|
146 |
+
markdown_output += "- **Main Entities**: [Identified names/companies]\n"
|
147 |
+
markdown_output += "- **Action Items**: [Key tasks identified]\n"
|
148 |
+
|
149 |
+
# Add document metadata
|
150 |
+
markdown_output += f"\n---\n*Document processed: {uploaded_file.name}*"
|
151 |
|
152 |
+
return markdown_output
|
153 |
+
|
154 |
+
# Custom CSS for dark theme with green text
|
155 |
+
custom_css = """
|
156 |
+
:root {
|
157 |
+
--primary: #00ff00;
|
158 |
+
--primary-50: #00ff0033;
|
159 |
+
--primary-100: #00ff0066;
|
160 |
+
--primary-200: #00ff0099;
|
161 |
+
--primary-300: #00ff00cc;
|
162 |
+
--secondary: #00cc00;
|
163 |
+
--secondary-50: #00cc0033;
|
164 |
+
--secondary-100: #00cc0066;
|
165 |
+
--secondary-200: #00cc0099;
|
166 |
+
--secondary-300: #00cc00cc;
|
167 |
+
--color-background-primary: #000000;
|
168 |
+
--color-background-secondary: #111111;
|
169 |
+
--color-background-tertiary: #222222;
|
170 |
+
--text-color: #00ff00;
|
171 |
+
--block-background-fill: #111111;
|
172 |
+
--block-border-color: #00aa00;
|
173 |
+
--block-label-text-color: #00ff00;
|
174 |
+
--block-title-text-color: #00ff00;
|
175 |
+
--input-background-fill: #111111;
|
176 |
+
--input-border-color: #00aa00;
|
177 |
+
--input-text-color: #00ff00;
|
178 |
+
}
|
179 |
+
|
180 |
+
body {
|
181 |
+
background-color: var(--color-background-primary) !important;
|
182 |
+
color: var(--text-color) !important;
|
183 |
+
}
|
184 |
+
|
185 |
+
.markdown-output {
|
186 |
+
padding: 20px;
|
187 |
+
border-radius: 8px;
|
188 |
+
background: var(--color-background-secondary);
|
189 |
+
border: 1px solid var(--block-border-color);
|
190 |
+
max-height: 600px;
|
191 |
+
overflow-y: auto;
|
192 |
+
color: var(--text-color) !important;
|
193 |
+
}
|
194 |
+
|
195 |
+
.markdown-output h1,
|
196 |
+
.markdown-output h2,
|
197 |
+
.markdown-output h3 {
|
198 |
+
color: var(--primary) !important;
|
199 |
+
border-bottom: 1px solid var(--primary-300);
|
200 |
+
}
|
201 |
+
|
202 |
+
.markdown-output a {
|
203 |
+
color: var(--secondary) !important;
|
204 |
+
}
|
205 |
+
|
206 |
+
.markdown-output code {
|
207 |
+
background-color: var(--color-background-tertiary);
|
208 |
+
color: var(--secondary);
|
209 |
+
}
|
210 |
+
|
211 |
+
.markdown-output pre {
|
212 |
+
background-color: var(--color-background-tertiary) !important;
|
213 |
+
border: 1px solid var(--block-border-color);
|
214 |
+
}
|
215 |
+
|
216 |
+
.markdown-output ul,
|
217 |
+
.markdown-output ol {
|
218 |
+
color: var(--text-color);
|
219 |
+
}
|
220 |
+
|
221 |
+
button {
|
222 |
+
background: var(--primary) !important;
|
223 |
+
color: black !important;
|
224 |
+
font-weight: bold !important;
|
225 |
+
}
|
226 |
+
|
227 |
+
button:hover {
|
228 |
+
background: var(--primary-300) !important;
|
229 |
+
}
|
230 |
+
"""
|
231 |
+
|
232 |
+
# Create dark theme
|
233 |
+
dark_green_theme = gr.themes.Default(
|
234 |
+
primary_hue="green",
|
235 |
+
secondary_hue="green",
|
236 |
+
neutral_hue="green",
|
237 |
+
).set(
|
238 |
+
background_fill_primary="#000000",
|
239 |
+
background_fill_secondary="#111111",
|
240 |
+
block_background_fill="#111111",
|
241 |
+
border_color_accent="#00aa00",
|
242 |
+
block_label_text_color="#00ff00",
|
243 |
+
body_text_color="#00ff00",
|
244 |
+
button_primary_text_color="#000000",
|
245 |
+
)
|
246 |
|
247 |
# --- GRADIO INTERFACE ---
|
248 |
+
with gr.Blocks(
|
249 |
+
title="DocSum - Document Summarizer",
|
250 |
+
theme=dark_green_theme,
|
251 |
+
css=custom_css
|
252 |
+
) as demo:
|
253 |
gr.Markdown("# π§Ύ DocSum")
|
254 |
gr.Markdown("Document Summarizer Powered by VLM β’ Developed by [Koshur AI](https://koshurai.com)")
|
255 |
|
|
|
272 |
|
273 |
submit_btn = gr.Button("π Analyze Document", variant="primary")
|
274 |
|
275 |
+
# Markdown output with custom class
|
276 |
output = gr.Markdown(
|
277 |
label="Analysis Results",
|
278 |
elem_classes=["markdown-output"]
|
|
|
284 |
outputs=output
|
285 |
)
|
286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
if __name__ == "__main__":
|
288 |
demo.launch()
|