Bennie12 commited on
Commit
a057b00
Β·
verified Β·
1 Parent(s): a1f6f42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -16
app.py CHANGED
@@ -16,23 +16,38 @@ def predict_image(file, mode):
16
  keywords = ', '.join(result['suspicious_keywords'])
17
  return status, confidence, keywords
18
 
19
- with gr.Blocks() as demo:
20
- gr.Markdown("## πŸ“© ι ζΈ¬θ©ι¨™θ¨Šζ― (ζ–‡ε­— + εœ–η‰‡)")
21
-
22
- with gr.Tab("文字預測"):
23
- text_inputs = gr.TextArea(label="θΌΈε…₯訊息")
24
- mode_radio_1 = gr.Radio(choices=["cnn", "bert", "both"], label="εˆ†ζžζ¨‘εΌ", value="cnn")
25
- text_buotton = gr.Button("ι–‹ε§‹εˆ†ζž")
26
- text_result =[gr.Textbox(label = "εˆ€ζ–·η΅ζžœ"),gr.Textbox(label = "ε―η–‘εˆ†ζ•Έ"),gr.Textbox(label = "ε―η–‘θ©žε½™")]
27
- text_buotton.click(fn=predict_text, inputs=[text_inputs, mode_radio_1], outputs=text_result)
28
-
29
- with gr.Tab("εœ–η‰‡ι ζΈ¬"):
30
- image_inputs = gr.TextArea(label="δΈŠε‚³εœ–η‰‡")
31
- mode_radio_2 = gr.Radio(choices=["cnn", "bert", "both"], label="εˆ†ζžζ¨‘εΌ", value="cnn")
32
- image_buotton = gr.Button("ι–‹ε§‹εˆ†ζž")
33
- image_result =[gr.Textbox(label = "εˆ€ζ–·η΅ζžœ"),gr.Textbox(label = "ε―η–‘εˆ†ζ•Έ"),gr.Textbox(label = "ε―η–‘θ©žε½™")]
34
- image_buotton.click(fn=predict_image, inputs=[image_inputs, mode_radio_2], outputs=image_result)
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
 
 
 
 
 
37
 
38
  demo.launch()
 
16
  keywords = ', '.join(result['suspicious_keywords'])
17
  return status, confidence, keywords
18
 
19
+ text_interface = gr.Interface(
20
+ fn=predict,
21
+ inputs=[
22
+ gr.Textbox(label="θΌΈε…₯訊息"),
23
+ gr.Radio(choices=["cnn", "bert", "both"], label="εˆ†ζžζ¨‘εΌ", value="cnn")
24
+ ],
25
+ outputs=[
26
+ gr.Textbox(label="εˆ€ζ–·η΅ζžœ"),
27
+ gr.Textbox(label="ε―η–‘εˆ†ζ•Έ"),
28
+ gr.Textbox(label="ε―η–‘θ©žε½™")
29
+ ],
30
+ allow_flagging="never"
31
+ )
 
 
 
32
 
33
+ image_interface = gr.Interface(
34
+ fn=predict_image,
35
+ inputs=[
36
+ gr.Image(type="filepath", label="δΈŠε‚³εœ–η‰‡"),
37
+ gr.Radio(choices=["cnn", "bert", "both"], label="εˆ†ζžζ¨‘εΌ", value="cnn")
38
+ ],
39
+ outputs=[
40
+ gr.Textbox(label="εˆ€ζ–·η΅ζžœ"),
41
+ gr.Textbox(label="ε―η–‘εˆ†ζ•Έ"),
42
+ gr.Textbox(label="ε―η–‘θ©žε½™")
43
+ ],
44
+ allow_flagging="never"
45
+ )
46
 
47
+ # ζ•΄εˆζˆ Tab 介青
48
+ demo = gr.TabbedInterface(
49
+ interface_list=[text_interface, image_interface],
50
+ tab_names=["文字預測", "εœ–η‰‡ι ζΈ¬"]
51
+ )
52
 
53
  demo.launch()