openfree commited on
Commit
74b6cd5
ยท
verified ยท
1 Parent(s): d27df0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -20
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. However, if social norms constrain married womenโ€™s activities outside the home, then marriage can independently reduce employment, even in the absence childbearing. Given the correlation in timing between childbirth and marriage, conventional estimates of child penalties will conflate these two effects. The paper studies the marriage penalty in South Asia, a context featuring conservative gender norms and low female labor force participation. The study introduces a split-sample, pseudo-panel approach that allows for the separation of marriage and child penalties even in the absence of individual-level panel data. Marriage reduces womenโ€™s labor force participation in South Asia by 12 percentage points, whereas the marginal penalty of childbearing is small. Consistent with the central roles of both opportunity costs and social norms, the marriage penalty is smaller among cohorts with higher education and less conservative gender attitudes."""
8
 
9
  clf = wbgtopic.WBGDocTopic()
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  @spaces.GPU(enable_queue=True, duration=50)
13
  def fn(inputs):
14
- return clf.suggest_topics(inputs)
15
-
16
 
17
- with gr.Blocks(title="WBG-Document-Topic-Classifier") as demo:
18
-
19
- text = gr.Textbox(
20
- value=SAMPLE_TEXT, label="Text", placeholder="Enter your text here"
21
- )
22
-
23
- output = gr.JSON(label="Suggested topics")
24
- submit_btn = gr.Button("Submit")
25
-
26
- # Submitting
27
- text.submit(
28
- fn=fn, inputs=[text], outputs=output
29
- )
 
 
 
 
 
 
 
30
  submit_btn.click(
31
- fn=fn, inputs=[text], outputs=output
 
 
32
  )
33
 
34
- demo.queue(default_concurrency_limit=5)
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)