leewatson commited on
Commit
5dd3265
ยท
verified ยท
1 Parent(s): f810d4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -7
app.py CHANGED
@@ -13,7 +13,12 @@ B: ๋„ˆ ์ง„์งœ ์™œ ์ด๋ž˜?
13
  """
14
 
15
  def run_pipeline(text, alpha, z, steps):
16
- report, img_b64, struct = analyze_dialogue(text, smooth_alpha=alpha, z_thresh=z, forecast_steps=steps)
 
 
 
 
 
17
  img_md = f"![plot](data:image/png;base64,{img_b64})" if img_b64 else ""
18
  return report, img_md, str(struct)
19
 
@@ -22,7 +27,11 @@ with gr.Blocks() as demo:
22
  gr.Markdown(INTRO)
23
 
24
  with gr.Row():
25
- text = gr.Textbox(label="๋Œ€ํ™” ์ž…๋ ฅ", lines=12, value="A: ๋„ˆ ์™œ ๋˜ ๋Šฆ์—ˆ์–ด?\nB: ๋ฏธ์•ˆํ•ด, ์ฐจ๊ฐ€ ๋ง‰ํ˜”์–ด.\nA: ๋ณ€๋ช…ํ•˜์ง€ ๋งˆ.\nB: ๋„ˆ ์ง„์งœ ์™œ ์ด๋ž˜?")
 
 
 
 
26
  with gr.Column():
27
  alpha = gr.Slider(0.1, 0.9, value=0.4, step=0.05, label="EMA ฮฑ(์Šค๋ฌด๋”ฉ ๊ฐ•๋„)")
28
  z = gr.Slider(1.0, 3.0, value=1.8, step=0.1, label="๊ธ‰๋ณ€ Z ์ž„๊ณ„๊ฐ’")
@@ -34,11 +43,24 @@ with gr.Blocks() as demo:
34
  img = gr.Markdown()
35
  struct = gr.Textbox(label="๋””๋ฒ„๊ทธ/๊ตฌ์กฐ ๋ฐ์ดํ„ฐ", lines=10)
36
 
37
- # api_name="predict" ๋กœ REST ๊ฒฝ๋กœ ๋…ธ์ถœ
38
- btn.click(run_pipeline, inputs=[text, alpha, z, steps], outputs=[report, img, struct], api_name="predict")
 
 
 
 
 
39
 
40
- # โ˜… Queue๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ผญ๋‹ˆ๋‹ค(Gradio ์„œ๋ฒ„๊ฐ€ ํ ๊ธฐ๋ฐ˜์ด๋ฉด gradio_client๊ฐ€ ํ›จ์”ฌ ์•ˆ์ •์ ).
41
- # launch ์ง์ „ queue()๋ฅผ ๋ฐ˜๋“œ์‹œ ํ˜ธ์ถœ.
42
  if __name__ == "__main__":
43
- demo.queue(concurrency_count=1, max_size=128)
 
 
 
 
 
 
 
 
 
 
44
  demo.launch(server_name="0.0.0.0", server_port=7860, show_error=True)
 
13
  """
14
 
15
  def run_pipeline(text, alpha, z, steps):
16
+ report, img_b64, struct = analyze_dialogue(
17
+ text,
18
+ smooth_alpha=alpha,
19
+ z_thresh=z,
20
+ forecast_steps=steps
21
+ )
22
  img_md = f"![plot](data:image/png;base64,{img_b64})" if img_b64 else ""
23
  return report, img_md, str(struct)
24
 
 
27
  gr.Markdown(INTRO)
28
 
29
  with gr.Row():
30
+ text = gr.Textbox(
31
+ label="๋Œ€ํ™” ์ž…๋ ฅ",
32
+ lines=12,
33
+ value="A: ๋„ˆ ์™œ ๋˜ ๋Šฆ์—ˆ์–ด?\nB: ๋ฏธ์•ˆํ•ด, ์ฐจ๊ฐ€ ๋ง‰ํ˜”์–ด.\nA: ๋ณ€๋ช…ํ•˜์ง€ ๋งˆ.\nB: ๋„ˆ ์ง„์งœ ์™œ ์ด๋ž˜?"
34
+ )
35
  with gr.Column():
36
  alpha = gr.Slider(0.1, 0.9, value=0.4, step=0.05, label="EMA ฮฑ(์Šค๋ฌด๋”ฉ ๊ฐ•๋„)")
37
  z = gr.Slider(1.0, 3.0, value=1.8, step=0.1, label="๊ธ‰๋ณ€ Z ์ž„๊ณ„๊ฐ’")
 
43
  img = gr.Markdown()
44
  struct = gr.Textbox(label="๋””๋ฒ„๊ทธ/๊ตฌ์กฐ ๋ฐ์ดํ„ฐ", lines=10)
45
 
46
+ # REST ๋…ธ์ถœ์„ ์œ„ํ•ด api_name ์œ ์ง€
47
+ btn.click(
48
+ run_pipeline,
49
+ inputs=[text, alpha, z, steps],
50
+ outputs=[report, img, struct],
51
+ api_name="predict"
52
+ )
53
 
 
 
54
  if __name__ == "__main__":
55
+ # Gradio ๋ฒ„์ „ ์ฐจ์ด๋ฅผ ํก์ˆ˜ํ•˜๋Š” queue() ํ˜ธ์ถœ
56
+ try:
57
+ # gradio>=4 ๊ณ„์—ด
58
+ demo.queue(default_concurrency_limit=1, max_size=128)
59
+ except TypeError:
60
+ try:
61
+ # ์ผ๋ถ€ 3.x ๊ณ„์—ด
62
+ demo.queue(concurrency_count=1, max_size=128)
63
+ except TypeError:
64
+ # ๋” ๊ตฌ๋ฒ„์ „: ์ธ์ž ์—†์ด
65
+ demo.queue()
66
  demo.launch(server_name="0.0.0.0", server_port=7860, show_error=True)