Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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 |
-
#
|
| 19 |
CUSTOM_CSS = """
|
| 20 |
.gradio-container {
|
| 21 |
-
font-family: '
|
| 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
|
|
|
|
|
|
|
|
|
|
| 418 |
with gr.Row():
|
| 419 |
-
|
| 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 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
stats_output = gr.Markdown("", label="π Analysis Results")
|
| 452 |
|
| 453 |
# Right panel - Examples moved to right side
|
| 454 |
with gr.Column(scale=1):
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 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.
|
| 474 |
output_graph = gr.HTML(label="")
|
| 475 |
|
| 476 |
-
with gr.
|
| 477 |
output_entity_viz = gr.HTML(label="")
|
| 478 |
|
| 479 |
# Functionality
|
|
@@ -504,10 +376,9 @@ def create_ui():
|
|
| 504 |
)
|
| 505 |
|
| 506 |
# Footer
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 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 |
|