Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,81 +1,41 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
("
|
| 13 |
-
(
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
("
|
| 21 |
-
("
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
ax.text(0.5, y, label, ha='center', va='center', fontsize=10)
|
| 40 |
-
|
| 41 |
-
# Draw arrows
|
| 42 |
-
arrows = [
|
| 43 |
-
(9, 8), # Start -> Load PDF
|
| 44 |
-
(8, 7), # Load PDF -> Extract Text
|
| 45 |
-
(7, 6), # Extract Text -> Text Valid?
|
| 46 |
-
(6, 5), # Text Valid? -> Split into Chunks (Yes)
|
| 47 |
-
(6, 1, 0.7, "No"), # Text Valid? -> End (No)
|
| 48 |
-
(5, 4), # Split into Chunks -> Process Chunks
|
| 49 |
-
(4, 3), # Process Chunks -> Chunk Eligible?
|
| 50 |
-
(3, 2.5), # Chunk Eligible? -> Summarize Chunk (Yes)
|
| 51 |
-
(3, 2, 0.3, "No"), # Chunk Eligible? -> Generate Visualizations (No)
|
| 52 |
-
(2.5, 2), # Summarize Chunk -> Generate Visualizations
|
| 53 |
-
(2, 1) # Generate Visualizations -> End
|
| 54 |
-
]
|
| 55 |
-
|
| 56 |
-
for start_y, end_y, *extras in arrows:
|
| 57 |
-
x_offset = extras[0] if extras else 0.5
|
| 58 |
-
label = extras[1] if len(extras) > 1 else ""
|
| 59 |
-
arrow = FancyArrowPatch((x_offset, start_y-0.4), (x_offset, end_y+0.4),
|
| 60 |
-
arrowstyle="->", mutation_scale=20, lw=1.5)
|
| 61 |
-
ax.add_patch(arrow)
|
| 62 |
-
if label:
|
| 63 |
-
ax.text(x_offset+0.1, (start_y+end_y)/2, label, fontsize=8, va='center')
|
| 64 |
-
|
| 65 |
-
plt.xlim(0, 1)
|
| 66 |
-
plt.ylim(0, 10)
|
| 67 |
-
plt.tight_layout()
|
| 68 |
-
|
| 69 |
-
# Save to buffer
|
| 70 |
-
buf = io.BytesIO()
|
| 71 |
-
fig.savefig(buf, format='png', bbox_inches='tight')
|
| 72 |
-
plt.close(fig)
|
| 73 |
-
buf.seek(0)
|
| 74 |
-
return Image.open(buf)
|
| 75 |
-
|
| 76 |
-
# Generate and save the flowchart
|
| 77 |
-
flowchart = create_process_flowchart()
|
| 78 |
-
flowchart.save('summary_process_flowchart.png')
|
| 79 |
|
| 80 |
|
| 81 |
|
|
|
|
| 1 |
+
```python
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
# Existing imports and code (omitted for brevity) remain unchanged until the launch section
|
| 6 |
+
|
| 7 |
+
if __name__ == "__main__":
|
| 8 |
+
logging.basicConfig(level=logging.INFO)
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
logger.info("Starting Gradio application on http://127.0.0.1:7860")
|
| 13 |
+
demo.launch(
|
| 14 |
+
share=False,
|
| 15 |
+
server_name="127.0.0.1",
|
| 16 |
+
server_port=7860,
|
| 17 |
+
debug=True # Enable debug mode for detailed error output
|
| 18 |
+
)
|
| 19 |
+
except Exception as e:
|
| 20 |
+
logger.error(f"Gradio launch failed: {str(e)}")
|
| 21 |
+
logger.info("Trying alternative port 7861...")
|
| 22 |
+
try:
|
| 23 |
+
demo.launch(
|
| 24 |
+
share=False,
|
| 25 |
+
server_name="127.0.0.1",
|
| 26 |
+
server_port=7861,
|
| 27 |
+
debug=True
|
| 28 |
+
)
|
| 29 |
+
except Exception as e2:
|
| 30 |
+
logger.error(f"Gradio launch failed on port 7861: {str(e2)}")
|
| 31 |
+
raise
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
**Changes**:
|
| 35 |
+
- Added explicit `server_name="127.0.0.1"` for local binding.
|
| 36 |
+
- Enabled `debug=True` for detailed Gradio logs.
|
| 37 |
+
- Added a fallback to try port 7861 if 7860 fails.
|
| 38 |
+
- Enhanced logging with `logging` module to capture initialization errors.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
|