Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files14 unmodified lines151617181819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314421222324266 unmodified lines29129229341729429529629729841942042142242342429930030130230330443043143243343443543643743843944044144244344444544644744844945045130530630730830931031131231331431531631731831932032132232332432532632732845545645745845946046146246346446546632933033133233333433533633733833934034134234334447334534634747634834935035124 unmodified lines37637737850750850951037938038138238338414 unmodified linesTITLE = "π GraphMind: Phi-3 Instruct Graph Explorer"SUBTITLE = "β¨ Extract and visualize knowledge graphs from any text in multiple languages"
# Enhanced Custom CSS for styling with improved visuals# Basic CSS for stylingCUSTOM_CSS = """.gradio-container { font-family: 'Inter', 'Segoe UI', Roboto, sans-serif; background: linear-gradient(to bottom, #f9fafb, #f3f4f6);}.gr-button-primary { background-color: #4f46e5 !important; border: none !important; color: white !important; border-radius: 8px !important;}.gr-button-primary:hover { background-color: #4338ca !important; transform: translateY(-1px); box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);}.gr-button-secondary { border-color: #4f46e5 !important; color: #4f46e5 !important; border-radius: 8px !important;}.gr-button-secondary:hover { background-color: #eef2ff !important; transform: translateY(-1px);}.gr-box, .gr-input, .gr-textarea, .gr-dropdown { border-radius: 8px !important; border: 1px solid #e5e7eb !important; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05) !important;}.gr-padded { padding: 16px !important;}.gr-form { border: none !important; background: transparent !important;}.gr-input:focus, .gr-textarea:focus, .gr-dropdown:focus { border-color: #4f46e5 !important; box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2) !important;}.gr-panel { border-radius: 12px !important; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important; background-color: white !important;}.gr-heading { font-weight: 700 !important; color: #111827 !important;}.gr-examples-table { border-radius: 8px !important; overflow: hidden !important; box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06) !important;}.gr-prose p { margin-bottom: 0.75rem !important; color: #4b5563 !important;}.gr-prose h1, .gr-prose h2, .gr-prose h3 { font-weight: 700 !important; color: #111827 !important;}.gr-tab { border-radius: 8px 8px 0 0 !important;}.gr-tab-selected { border-color: #4f46e5 !important; color: #4f46e5 !important; font-weight: 600 !important;}.header-container { margin-bottom: 24px !important;}.sidebar-container { background-color: white !important; border-radius: 12px !important; padding: 16px !important; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;}.visualization-container { margin-top: 24px !important;}.app-title { background: linear-gradient(90deg, #4f46e5, #8b5cf6) !important; -webkit-background-clip: text !important; -webkit-text-fill-color: transparent !important; font-weight: 800 !important; font-size: 2.25rem !important; margin-bottom: 0.5rem !important;}.app-subtitle { color: #6b7280 !important; font-size: 1.25rem !important; margin-bottom: 2rem !important;}.examples-container { background-color: white !important; border-radius: 12px !important; padding: 16px !important; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important; margin-bottom: 16px !important;}.results-container { background-color: #f8fafc !important; padding: 20px !important; border-radius: 12px !important; margin-top: 1rem !important; margin-bottom: 1rem !important; border: 1px solid #e2e8f0 !important;}.language-badge { display: inline-block !important; background-color: #4f46e5 !important; color: white !important; padding: 4px 12px !important; border-radius: 16px !important; font-weight: 600 !important; font-size: 0.875rem !important; margin-right: 8px !important;}.graph-container iframe { width: 100% !important; height: 700px !important; border-radius: 12px !important; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important; font-family: 'Segoe UI', Roboto, sans-serif;}"""
266 unmodified lines first_example_cache = generate_first_example_cache() with gr.Blocks(css=CUSTOM_CSS, title=TITLE) as demo: # Header with enhanced styling # Header gr.Markdown(f"# {TITLE}") gr.Markdown(f"{SUBTITLE}") with gr.Row(): with gr.Column(): gr.Markdown(f"<h1 class='app-title'>{TITLE}</h1>") gr.Markdown(f"<p class='app-subtitle'>{SUBTITLE}</p>") with gr.Row(): gr.Markdown("<span class='language-badge'>English</span><span class='language-badge'>Korean</span><span class='language-badge'>+ More</span>") gr.Markdown("π **Multilingual Support Available**") # Main content area - redesigned layout with gr.Row(): # Left panel - Input controls with gr.Column(scale=1): with gr.Box(): input_model = gr.Dropdown( MODEL_LIST, label="π€ Select Model", info="Choose a model to process your text", value=MODEL_LIST[0] if MODEL_LIST else None ) input_text = gr.TextArea( label="π Input Text", info="Enter text in any language to extract a knowledge graph", placeholder="Enter text here...", lines=8, value=EXAMPLES[0][0] # Pre-fill with first example ) with gr.Row(): submit_button = gr.Button("π Extract & Visualize", variant="primary", scale=2) clear_button = gr.Button("π Clear", variant="secondary", scale=1) # Statistics will appear here stats_output = gr.Markdown("", label="π Analysis Results") input_model = gr.Dropdown( MODEL_LIST, label="π€ Select Model", info="Choose a model to process your text", value=MODEL_LIST[0] if MODEL_LIST else None ) input_text = gr.TextArea( label="π Input Text", info="Enter text in any language to extract a knowledge graph", placeholder="Enter text here...", lines=8, value=EXAMPLES[0][0] # Pre-fill with first example ) with gr.Row(): submit_button = gr.Button("π Extract & Visualize", variant="primary", scale=2) clear_button = gr.Button("π Clear", variant="secondary", scale=1) # Statistics will appear here stats_output = gr.Markdown("", label="π Analysis Results") # Right panel - Examples moved to right side with gr.Column(scale=1): with gr.Box(): gr.Markdown("<h3>π Example Texts</h3>") # Removed elem_classes parameter that was causing the error gr.Examples( examples=EXAMPLES, inputs=input_text, label="" ) # JSON output moved to right side as well with gr.Accordion("π JSON Data", open=False): output_json = gr.JSON(label="") gr.Markdown("## π Example Texts") gr.Examples( examples=EXAMPLES, inputs=input_text, label="" ) # JSON output moved to right side as well with gr.Accordion("π JSON Data", open=False): output_json = gr.JSON(label="") # Full width visualization area at the bottom with gr.Row(): with gr.Column(): # Tab container for visualizations with gr.Tabs(): with gr.Tab("π§© Knowledge Graph"): with gr.TabItem("π§© Knowledge Graph"): output_graph = gr.HTML(label="") with gr.Tab("π·οΈ Entity Recognition"): with gr.TabItem("π·οΈ Entity Recognition"): output_entity_viz = gr.HTML(label="") # Functionality24 unmodified lines ) # Footer with gr.Row(): gr.Markdown("---") gr.Markdown("π **Instructions:** Enter text in any language, select a model, and click 'Extract & Visualize' to generate a knowledge graph.") gr.Markdown("π οΈ Powered by Phi-3 Instruct Graph | Emergent Methods") gr.Markdown("---") gr.Markdown("π **Instructions:** Enter text in any language, select a model, and click 'Extract & Visualize' to generate a knowledge graph.") gr.Markdown("π οΈ Powered by Phi-3 Instruct Graph | Emergent Methods") return demo
app.py+43-172