tejovanth commited on
Commit
fa7e538
·
verified ·
1 Parent(s): ac73cea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -78
app.py CHANGED
@@ -1,81 +1,41 @@
1
- import matplotlib.pyplot as plt
2
- from matplotlib.patches import FancyBboxPatch, Circle, FancyArrowPatch
3
- import io
4
- from PIL import Image
5
-
6
- def create_process_flowchart():
7
- fig, ax = plt.subplots(figsize=(8, 10))
8
- ax.axis('off')
9
-
10
- # Define node positions (y decreases as we move down)
11
- nodes = [
12
- ("Start", 9, "circle", "lightgreen"),
13
- ("Load PDF", 8, "box", "lightblue"),
14
- ("Extract Text", 7, "box", "lightblue"),
15
- ("Text Valid?", 6, "diamond", "lightyellow"),
16
- ("Split into Chunks", 5, "box", "lightblue"),
17
- ("Process Chunks", 4, "box", "lightblue"),
18
- ("Chunk Eligible?", 3, "diamond", "lightyellow"),
19
- ("Summarize Chunk", 2.5, "box", "lightblue"),
20
- ("Generate Visualizations", 2, "box", "lightblue"),
21
- ("End", 1, "circle", "lightcoral")
22
- ]
23
-
24
- # Draw nodes
25
- for label, y, shape, color in nodes:
26
- if shape == "circle":
27
- node = Circle((0.5, y), 0.4, facecolor=color, edgecolor="black")
28
- ax.add_patch(node)
29
- ax.text(0.5, y, label, ha='center', va='center', fontsize=10)
30
- elif shape == "box":
31
- node = FancyBboxPatch((0.3, y-0.3), 0.4, 0.6, boxstyle="round,pad=0.3",
32
- facecolor=color, edgecolor="black")
33
- ax.add_patch(node)
34
- ax.text(0.5, y, label, ha='center', va='center', fontsize=10)
35
- elif shape == "diamond":
36
- points = [(0.5, y+0.4), (0.7, y), (0.5, y-0.4), (0.3, y)]
37
- node = plt.Polygon(points, facecolor=color, edgecolor="black")
38
- ax.add_patch(node)
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