File size: 1,454 Bytes
4fe5752
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# gradio_app.py
import gradio as gr
import requests
import os

# URL of the backend API (if hosted separately, otherwise use local endpoints)
API_URL = os.getenv("API_URL", "http://localhost:8000")

def extract_interface(text):
    response = requests.post(f"{API_URL}/extract", json={"text": text})
    if response.ok:
        return response.json()["entities"]
    else:
        return {"error": response.text}

def summarize_interface(text):
    response = requests.post(f"{API_URL}/summarize", json={"text": text})
    if response.ok:
        return response.json()["summary"]
    else:
        return {"error": response.text}

with gr.Blocks(title="Materials AI Extraction Demo") as demo:
    gr.Markdown("## Materials Science AI Extraction")
    with gr.Tabs():
        with gr.TabItem("Extract Entities"):
            input_text = gr.Textbox(label="Enter Materials Science Text", lines=5)
            output_entities = gr.JSON(label="Extracted Entities")
            extract_btn = gr.Button("Extract")
            extract_btn.click(fn=extract_interface, inputs=input_text, outputs=output_entities)
        with gr.TabItem("Summarize Text"):
            summary_input = gr.Textbox(label="Enter Text to Summarize", lines=5)
            summary_output = gr.Textbox(label="Summary")
            summarize_btn = gr.Button("Summarize")
            summarize_btn.click(fn=summarize_interface, inputs=summary_input, outputs=summary_output)

demo.launch()