Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files14 unmodified lines15161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147266 unmodified lines41441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847924 unmodified lines50450550650750850951051151251314 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 visualsCUSTOM_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;}"""266 unmodified linesfirst_example_cache = generate_first_example_cache()with gr.Blocks(css=CUSTOM_CSS, title=TITLE) as demo:# Header with enhanced stylingwith 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>")# Main content area - redesigned layoutwith gr.Row():# Left panel - Input controlswith 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 herestats_output = gr.Markdown("", label="π Analysis Results")# Right panel - Examples moved to right sidewith gr.Column(scale=1):with gr.Box():gr.Markdown("<h3>π Example Texts</h3>")# Removed elem_classes parameter that was causing the errorgr.Examples(examples=EXAMPLES,inputs=input_text,label="")# JSON output moved to right side as wellwith gr.Accordion("π JSON Data", open=False):output_json = gr.JSON(label="")# Full width visualization area at the bottomwith gr.Row():with gr.Column():# Tab container for visualizationswith gr.Tabs():with gr.Tab("π§© Knowledge Graph"):output_graph = gr.HTML(label="")with gr.Tab("π·οΈ Entity Recognition"):output_entity_viz = gr.HTML(label="")# Functionality24 unmodified lines)# Footerwith 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")return demo14 unmodified lines15161718192021222324266 unmodified lines29129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035124 unmodified lines37637737837938038138238338414 unmodified linesTITLE = "π GraphMind: Phi-3 Instruct Graph Explorer"SUBTITLE = "β¨ Extract and visualize knowledge graphs from any text in multiple languages"# Basic CSS for stylingCUSTOM_CSS = """.gradio-container {font-family: 'Segoe UI', Roboto, sans-serif;}"""266 unmodified linesfirst_example_cache = generate_first_example_cache()with gr.Blocks(css=CUSTOM_CSS, title=TITLE) as demo:# Headergr.Markdown(f"# {TITLE}")gr.Markdown(f"{SUBTITLE}")with gr.Row():gr.Markdown("π **Multilingual Support Available**")# Main content area - redesigned layoutwith gr.Row():# Left panel - Input controlswith gr.Column(scale=1):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 herestats_output = gr.Markdown("", label="π Analysis Results")# Right panel - Examples moved to right sidewith gr.Column(scale=1):gr.Markdown("## π Example Texts")gr.Examples(examples=EXAMPLES,inputs=input_text,label="")# JSON output moved to right side as wellwith gr.Accordion("π JSON Data", open=False):output_json = gr.JSON(label="")# Full width visualization area at the bottomwith gr.Row():with gr.Column():# Tab container for visualizationswith gr.Tabs():with gr.TabItem("π§© Knowledge Graph"):output_graph = gr.HTML(label="")with gr.TabItem("π·οΈ Entity Recognition"):output_entity_viz = gr.HTML(label="")# Functionality24 unmodified lines)# Footergr.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