Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,65 @@
|
|
| 1 |
import json
|
| 2 |
import gradio as gr
|
| 3 |
import spaces
|
| 4 |
-
|
| 5 |
import wbgtopic
|
|
|
|
| 6 |
|
| 7 |
-
SAMPLE_TEXT = """A growing literature attributes gender inequality in labor market outcomes in part to the reduction in female labor supply after childbirth, the child penalty
|
| 8 |
|
| 9 |
clf = wbgtopic.WBGDocTopic()
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
@spaces.GPU(enable_queue=True, duration=50)
|
| 13 |
def fn(inputs):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
submit_btn.click(
|
| 31 |
-
fn=fn,
|
|
|
|
|
|
|
| 32 |
)
|
| 33 |
|
| 34 |
-
demo.
|
| 35 |
-
demo.launch(debug=True)
|
|
|
|
| 1 |
import json
|
| 2 |
import gradio as gr
|
| 3 |
import spaces
|
|
|
|
| 4 |
import wbgtopic
|
| 5 |
+
from topic_translator import translate_topics # ์๋ก ๋ง๋ค ํ์ผ์
๋๋ค
|
| 6 |
|
| 7 |
+
SAMPLE_TEXT = """A growing literature attributes gender inequality in labor market outcomes in part to the reduction in female labor supply after childbirth, the child penalty..."""
|
| 8 |
|
| 9 |
clf = wbgtopic.WBGDocTopic()
|
| 10 |
|
| 11 |
+
def process_results(results):
|
| 12 |
+
# ๊ฒฐ๊ณผ๋ฅผ ๋ณด๊ธฐ ์ข๊ฒ ๊ฐ๊ณต
|
| 13 |
+
if not results or not results[0]:
|
| 14 |
+
return []
|
| 15 |
+
|
| 16 |
+
# ์ฒซ ๋ฒ์งธ ๋ฌธ์์ ๊ฒฐ๊ณผ๋ง ์ฌ์ฉ (๋จ์ผ ๋ฌธ์ ๊ธฐ์ค)
|
| 17 |
+
topics = results[0]
|
| 18 |
+
|
| 19 |
+
# ์์ 5๊ฐ ์ฃผ์ ๋ง ์ ํ
|
| 20 |
+
top_topics = sorted(topics, key=lambda x: x['score_mean'], reverse=True)[:5]
|
| 21 |
+
|
| 22 |
+
# ๊ฐ ์ฃผ์ ์ ์ ์๋ฅผ ํผ์ผํธ๋ก ๋ณํํ๊ณ ํ๊ธ๋ก ๋ฒ์ญ
|
| 23 |
+
formatted_topics = []
|
| 24 |
+
for topic in top_topics:
|
| 25 |
+
formatted_topic = {
|
| 26 |
+
'label': translate_topics.get(topic['label'], topic['label']),
|
| 27 |
+
'score': round(topic['score_mean'] * 100, 1),
|
| 28 |
+
'confidence': round((1 - topic['score_std']) * 100, 1)
|
| 29 |
+
}
|
| 30 |
+
formatted_topics.append(formatted_topic)
|
| 31 |
+
|
| 32 |
+
return formatted_topics
|
| 33 |
|
| 34 |
@spaces.GPU(enable_queue=True, duration=50)
|
| 35 |
def fn(inputs):
|
| 36 |
+
raw_results = clf.suggest_topics(inputs)
|
| 37 |
+
return process_results(raw_results)
|
| 38 |
|
| 39 |
+
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
| 40 |
+
with gr.Blocks(title="๋ฌธ์ ์ฃผ์ ๋ถ์๊ธฐ") as demo:
|
| 41 |
+
gr.Markdown("## ๐ ๋ฌธ์ ์ฃผ์ ๋ถ์๊ธฐ")
|
| 42 |
+
gr.Markdown("๋ฌธ์๋ฅผ ์
๋ ฅํ๋ฉด ๊ด๋ จ๋ ์ฃผ์ ๋ค์ ๋ถ์ํ์ฌ ๋ณด์ฌ์ค๋๋ค.")
|
| 43 |
+
|
| 44 |
+
with gr.Row():
|
| 45 |
+
text = gr.Textbox(
|
| 46 |
+
value=SAMPLE_TEXT,
|
| 47 |
+
label="๋ถ์ํ ํ
์คํธ",
|
| 48 |
+
placeholder="์ฌ๊ธฐ์ ๋ถ์ํ ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์",
|
| 49 |
+
lines=5
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
with gr.Row():
|
| 53 |
+
submit_btn = gr.Button("๋ถ์ ์์", variant="primary")
|
| 54 |
+
|
| 55 |
+
with gr.Row():
|
| 56 |
+
output = gr.JSON(label="๋ถ์ ๊ฒฐ๊ณผ")
|
| 57 |
+
|
| 58 |
+
# ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
| 59 |
submit_btn.click(
|
| 60 |
+
fn=fn,
|
| 61 |
+
inputs=[text],
|
| 62 |
+
outputs=output
|
| 63 |
)
|
| 64 |
|
| 65 |
+
demo.launch(debug=True)
|
|
|