import gradio as gr
import time # 模拟处理耗时
nlp = spacy.load("en_core_web_md")
def process_api(input_text):
# 这里编写实际的后端处理逻辑
return {
"status": "success",
"result": f"Processed: {input_text.upper()}",
"timestamp": time.time()
}
# 设置API格式为JSON
gr.Interface(
fn=process_api,
inputs="text",
outputs="json",
title="Backend API",
allow_flagging="never"
).launch()
# import gradio as gr
# import spacy
# from spacy import displacy
# import pandas as pd
# import time
# nlp = spacy.load("en_core_web_md")
# HTML_WRAPPER = "
{}
"
# def show_spatial_ent_table(doc):
# rows = []
# for i, ent in enumerate(doc.ents):
# rows.append(f"{i+1} | {ent.text} | {ent.label_} |
")
# table_html = "Index | Entity | Label |
" + "".join(rows) + "
"
# return table_html
# def process_api(input_text):
# doc = nlp(input_text)
# html_ent = displacy.render(doc, style="ent")
# html_ent = HTML_WRAPPER.format(html_ent.replace("\n", ""))
# html_table = show_spatial_ent_table(doc)
# final_html = html_ent + "
" + html_table
# return {
# "data": [{"html": final_html}],
# "timestamp": time.time()
# }
# gr.Interface(
# fn=process_api,
# inputs="text",
# outputs="json",
# allow_flagging="never",
# title="Backend API"
# ).launch()