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