Spaces:
Sleeping
Sleeping
Shunfeng Zheng
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,24 +7,24 @@ import pandas as pd
|
|
| 7 |
|
| 8 |
# os.system("python -m spacy download en_core_web_md")
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
#
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
|
| 30 |
# import gradio as gr
|
|
@@ -33,31 +33,31 @@ import pandas as pd
|
|
| 33 |
# import pandas as pd
|
| 34 |
# import time
|
| 35 |
|
| 36 |
-
nlp = spacy.load("en_core_web_md")
|
| 37 |
-
HTML_WRAPPER = "<div style='padding: 10px;'>{}</div>"
|
| 38 |
|
| 39 |
-
def show_spatial_ent_table(doc):
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
def process_api(input_text):
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
-
gr.Interface(
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
).launch()
|
|
|
|
| 7 |
|
| 8 |
# os.system("python -m spacy download en_core_web_md")
|
| 9 |
|
| 10 |
+
nlp = spacy.load("en_core_web_md")
|
| 11 |
+
def process_api(input_text):
|
| 12 |
+
# 这里编写实际的后端处理逻辑
|
| 13 |
|
| 14 |
+
return {
|
| 15 |
+
"status": "success",
|
| 16 |
+
"result": f"Processed: {input_text.upper()}",
|
| 17 |
+
"timestamp": time.time()
|
| 18 |
+
}
|
| 19 |
|
| 20 |
+
# 设置API格式为JSON
|
| 21 |
+
gr.Interface(
|
| 22 |
+
fn=process_api,
|
| 23 |
+
inputs="text",
|
| 24 |
+
outputs="json",
|
| 25 |
+
title="Backend API",
|
| 26 |
+
allow_flagging="never"
|
| 27 |
+
).launch()
|
| 28 |
|
| 29 |
|
| 30 |
# import gradio as gr
|
|
|
|
| 33 |
# import pandas as pd
|
| 34 |
# import time
|
| 35 |
|
| 36 |
+
# nlp = spacy.load("en_core_web_md")
|
| 37 |
+
# HTML_WRAPPER = "<div style='padding: 10px;'>{}</div>"
|
| 38 |
|
| 39 |
+
# def show_spatial_ent_table(doc):
|
| 40 |
+
# rows = []
|
| 41 |
+
# for i, ent in enumerate(doc.ents):
|
| 42 |
+
# rows.append(f"<tr><td>{i+1}</td><td>{ent.text}</td><td>{ent.label_}</td></tr>")
|
| 43 |
+
# table_html = "<table border='1'><tr><th>Index</th><th>Entity</th><th>Label</th></tr>" + "".join(rows) + "</table>"
|
| 44 |
+
# return table_html
|
| 45 |
|
| 46 |
+
# def process_api(input_text):
|
| 47 |
+
# doc = nlp(input_text)
|
| 48 |
+
# html_ent = displacy.render(doc, style="ent")
|
| 49 |
+
# html_ent = HTML_WRAPPER.format(html_ent.replace("\n", ""))
|
| 50 |
+
# html_table = show_spatial_ent_table(doc)
|
| 51 |
+
# final_html = html_ent + "<br>" + html_table
|
| 52 |
+
# return {
|
| 53 |
+
# "data": [{"html": final_html}],
|
| 54 |
+
# "timestamp": time.time()
|
| 55 |
+
# }
|
| 56 |
|
| 57 |
+
# gr.Interface(
|
| 58 |
+
# fn=process_api,
|
| 59 |
+
# inputs="text",
|
| 60 |
+
# outputs="json",
|
| 61 |
+
# allow_flagging="never",
|
| 62 |
+
# title="Backend API"
|
| 63 |
+
# ).launch()
|