ginipick commited on
Commit
b852bf5
Β·
verified Β·
1 Parent(s): 91a6397

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -172
app.py CHANGED
@@ -15,133 +15,10 @@ import pickle
15
  TITLE = "🌐 GraphMind: Phi-3 Instruct Graph Explorer"
16
  SUBTITLE = "✨ Extract and visualize knowledge graphs from any text in multiple languages"
17
 
18
- # Enhanced Custom CSS for styling with improved visuals
19
  CUSTOM_CSS = """
20
  .gradio-container {
21
- font-family: 'Inter', 'Segoe UI', Roboto, sans-serif;
22
- background: linear-gradient(to bottom, #f9fafb, #f3f4f6);
23
- }
24
- .gr-button-primary {
25
- background-color: #4f46e5 !important;
26
- border: none !important;
27
- color: white !important;
28
- border-radius: 8px !important;
29
- }
30
- .gr-button-primary:hover {
31
- background-color: #4338ca !important;
32
- transform: translateY(-1px);
33
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
34
- }
35
- .gr-button-secondary {
36
- border-color: #4f46e5 !important;
37
- color: #4f46e5 !important;
38
- border-radius: 8px !important;
39
- }
40
- .gr-button-secondary:hover {
41
- background-color: #eef2ff !important;
42
- transform: translateY(-1px);
43
- }
44
- .gr-box, .gr-input, .gr-textarea, .gr-dropdown {
45
- border-radius: 8px !important;
46
- border: 1px solid #e5e7eb !important;
47
- box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05) !important;
48
- }
49
- .gr-padded {
50
- padding: 16px !important;
51
- }
52
- .gr-form {
53
- border: none !important;
54
- background: transparent !important;
55
- }
56
- .gr-input:focus, .gr-textarea:focus, .gr-dropdown:focus {
57
- border-color: #4f46e5 !important;
58
- box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2) !important;
59
- }
60
- .gr-panel {
61
- border-radius: 12px !important;
62
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
63
- background-color: white !important;
64
- }
65
- .gr-heading {
66
- font-weight: 700 !important;
67
- color: #111827 !important;
68
- }
69
- .gr-examples-table {
70
- border-radius: 8px !important;
71
- overflow: hidden !important;
72
- box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06) !important;
73
- }
74
- .gr-prose p {
75
- margin-bottom: 0.75rem !important;
76
- color: #4b5563 !important;
77
- }
78
- .gr-prose h1, .gr-prose h2, .gr-prose h3 {
79
- font-weight: 700 !important;
80
- color: #111827 !important;
81
- }
82
- .gr-tab {
83
- border-radius: 8px 8px 0 0 !important;
84
- }
85
- .gr-tab-selected {
86
- border-color: #4f46e5 !important;
87
- color: #4f46e5 !important;
88
- font-weight: 600 !important;
89
- }
90
- .header-container {
91
- margin-bottom: 24px !important;
92
- }
93
- .sidebar-container {
94
- background-color: white !important;
95
- border-radius: 12px !important;
96
- padding: 16px !important;
97
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
98
- }
99
- .visualization-container {
100
- margin-top: 24px !important;
101
- }
102
- .app-title {
103
- background: linear-gradient(90deg, #4f46e5, #8b5cf6) !important;
104
- -webkit-background-clip: text !important;
105
- -webkit-text-fill-color: transparent !important;
106
- font-weight: 800 !important;
107
- font-size: 2.25rem !important;
108
- margin-bottom: 0.5rem !important;
109
- }
110
- .app-subtitle {
111
- color: #6b7280 !important;
112
- font-size: 1.25rem !important;
113
- margin-bottom: 2rem !important;
114
- }
115
- .examples-container {
116
- background-color: white !important;
117
- border-radius: 12px !important;
118
- padding: 16px !important;
119
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
120
- margin-bottom: 16px !important;
121
- }
122
- .results-container {
123
- background-color: #f8fafc !important;
124
- padding: 20px !important;
125
- border-radius: 12px !important;
126
- margin-top: 1rem !important;
127
- margin-bottom: 1rem !important;
128
- border: 1px solid #e2e8f0 !important;
129
- }
130
- .language-badge {
131
- display: inline-block !important;
132
- background-color: #4f46e5 !important;
133
- color: white !important;
134
- padding: 4px 12px !important;
135
- border-radius: 16px !important;
136
- font-weight: 600 !important;
137
- font-size: 0.875rem !important;
138
- margin-right: 8px !important;
139
- }
140
- .graph-container iframe {
141
- width: 100% !important;
142
- height: 700px !important;
143
- border-radius: 12px !important;
144
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
145
  }
146
  """
147
 
@@ -414,66 +291,61 @@ def create_ui():
414
  first_example_cache = generate_first_example_cache()
415
 
416
  with gr.Blocks(css=CUSTOM_CSS, title=TITLE) as demo:
417
- # Header with enhanced styling
 
 
 
418
  with gr.Row():
419
- with gr.Column():
420
- gr.Markdown(f"<h1 class='app-title'>{TITLE}</h1>")
421
- gr.Markdown(f"<p class='app-subtitle'>{SUBTITLE}</p>")
422
-
423
- with gr.Row():
424
- gr.Markdown("<span class='language-badge'>English</span><span class='language-badge'>Korean</span><span class='language-badge'>+ More</span>")
425
 
426
  # Main content area - redesigned layout
427
  with gr.Row():
428
  # Left panel - Input controls
429
  with gr.Column(scale=1):
430
- with gr.Box():
431
- input_model = gr.Dropdown(
432
- MODEL_LIST,
433
- label="πŸ€– Select Model",
434
- info="Choose a model to process your text",
435
- value=MODEL_LIST[0] if MODEL_LIST else None
436
- )
437
-
438
- input_text = gr.TextArea(
439
- label="πŸ“ Input Text",
440
- info="Enter text in any language to extract a knowledge graph",
441
- placeholder="Enter text here...",
442
- lines=8,
443
- value=EXAMPLES[0][0] # Pre-fill with first example
444
- )
445
-
446
- with gr.Row():
447
- submit_button = gr.Button("πŸš€ Extract & Visualize", variant="primary", scale=2)
448
- clear_button = gr.Button("πŸ”„ Clear", variant="secondary", scale=1)
449
-
450
- # Statistics will appear here
451
- stats_output = gr.Markdown("", label="πŸ” Analysis Results")
452
 
453
  # Right panel - Examples moved to right side
454
  with gr.Column(scale=1):
455
- with gr.Box():
456
- gr.Markdown("<h3>πŸ“š Example Texts</h3>")
457
- # Removed elem_classes parameter that was causing the error
458
- gr.Examples(
459
- examples=EXAMPLES,
460
- inputs=input_text,
461
- label=""
462
- )
463
-
464
- # JSON output moved to right side as well
465
- with gr.Accordion("πŸ“Š JSON Data", open=False):
466
- output_json = gr.JSON(label="")
467
 
468
  # Full width visualization area at the bottom
469
  with gr.Row():
470
  with gr.Column():
471
  # Tab container for visualizations
472
  with gr.Tabs():
473
- with gr.Tab("🧩 Knowledge Graph"):
474
  output_graph = gr.HTML(label="")
475
 
476
- with gr.Tab("🏷️ Entity Recognition"):
477
  output_entity_viz = gr.HTML(label="")
478
 
479
  # Functionality
@@ -504,10 +376,9 @@ def create_ui():
504
  )
505
 
506
  # Footer
507
- with gr.Row():
508
- gr.Markdown("---")
509
- gr.Markdown("πŸ“‹ **Instructions:** Enter text in any language, select a model, and click 'Extract & Visualize' to generate a knowledge graph.")
510
- gr.Markdown("πŸ› οΈ Powered by Phi-3 Instruct Graph | Emergent Methods")
511
 
512
  return demo
513
 
 
15
  TITLE = "🌐 GraphMind: Phi-3 Instruct Graph Explorer"
16
  SUBTITLE = "✨ Extract and visualize knowledge graphs from any text in multiple languages"
17
 
18
+ # Basic CSS for styling
19
  CUSTOM_CSS = """
20
  .gradio-container {
21
+ font-family: 'Segoe UI', Roboto, sans-serif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  }
23
  """
24
 
 
291
  first_example_cache = generate_first_example_cache()
292
 
293
  with gr.Blocks(css=CUSTOM_CSS, title=TITLE) as demo:
294
+ # Header
295
+ gr.Markdown(f"# {TITLE}")
296
+ gr.Markdown(f"{SUBTITLE}")
297
+
298
  with gr.Row():
299
+ gr.Markdown("🌍 **Multilingual Support Available**")
 
 
 
 
 
300
 
301
  # Main content area - redesigned layout
302
  with gr.Row():
303
  # Left panel - Input controls
304
  with gr.Column(scale=1):
305
+ input_model = gr.Dropdown(
306
+ MODEL_LIST,
307
+ label="πŸ€– Select Model",
308
+ info="Choose a model to process your text",
309
+ value=MODEL_LIST[0] if MODEL_LIST else None
310
+ )
311
+
312
+ input_text = gr.TextArea(
313
+ label="πŸ“ Input Text",
314
+ info="Enter text in any language to extract a knowledge graph",
315
+ placeholder="Enter text here...",
316
+ lines=8,
317
+ value=EXAMPLES[0][0] # Pre-fill with first example
318
+ )
319
+
320
+ with gr.Row():
321
+ submit_button = gr.Button("πŸš€ Extract & Visualize", variant="primary", scale=2)
322
+ clear_button = gr.Button("πŸ”„ Clear", variant="secondary", scale=1)
323
+
324
+ # Statistics will appear here
325
+ stats_output = gr.Markdown("", label="πŸ” Analysis Results")
 
326
 
327
  # Right panel - Examples moved to right side
328
  with gr.Column(scale=1):
329
+ gr.Markdown("## πŸ“š Example Texts")
330
+ gr.Examples(
331
+ examples=EXAMPLES,
332
+ inputs=input_text,
333
+ label=""
334
+ )
335
+
336
+ # JSON output moved to right side as well
337
+ with gr.Accordion("πŸ“Š JSON Data", open=False):
338
+ output_json = gr.JSON(label="")
 
 
339
 
340
  # Full width visualization area at the bottom
341
  with gr.Row():
342
  with gr.Column():
343
  # Tab container for visualizations
344
  with gr.Tabs():
345
+ with gr.TabItem("🧩 Knowledge Graph"):
346
  output_graph = gr.HTML(label="")
347
 
348
+ with gr.TabItem("🏷️ Entity Recognition"):
349
  output_entity_viz = gr.HTML(label="")
350
 
351
  # Functionality
 
376
  )
377
 
378
  # Footer
379
+ gr.Markdown("---")
380
+ gr.Markdown("πŸ“‹ **Instructions:** Enter text in any language, select a model, and click 'Extract & Visualize' to generate a knowledge graph.")
381
+ gr.Markdown("πŸ› οΈ Powered by Phi-3 Instruct Graph | Emergent Methods")
 
382
 
383
  return demo
384