Commit ยท
df182ba
1
Parent(s): ac5ec03
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import random
|
| 4 |
+
import time
|
| 5 |
+
from updated_predict import working_func
|
| 6 |
+
|
| 7 |
+
theme = gr.themes.Soft(
|
| 8 |
+
primary_hue="emerald",
|
| 9 |
+
secondary_hue="teal",
|
| 10 |
+
neutral_hue="indigo",
|
| 11 |
+
# text_size="text_lg",
|
| 12 |
+
# radius_size="radius_lg",
|
| 13 |
+
).set(
|
| 14 |
+
#body_background_fill='*checkbox_label_background_fill',
|
| 15 |
+
#body_background_fill='*block_title_background_fill',
|
| 16 |
+
body_background_fill='*background_fill_secondary',
|
| 17 |
+
background_fill_primary='*neutral_200',
|
| 18 |
+
block_background_fill='*table_even_background_fill',
|
| 19 |
+
button_border_width='*block_title_border_width',
|
| 20 |
+
button_shadow='*button_shadow_hover'
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def flip_text(x):
|
| 25 |
+
return x[::-1]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def flip_image(x):
|
| 29 |
+
return np.fliplr(x)
|
| 30 |
+
|
| 31 |
+
def diagnosed_huxi():
|
| 32 |
+
return "ๅผๅธ็ง"
|
| 33 |
+
|
| 34 |
+
def diagnosed_shennei():
|
| 35 |
+
return "็ฅ็ปๅ
็ง"
|
| 36 |
+
|
| 37 |
+
def diagnosed_xiaohua():
|
| 38 |
+
return "ๅ
็ง ๆถๅ็ง/่่ ็ง"
|
| 39 |
+
|
| 40 |
+
def diagnosed_xinnei():
|
| 41 |
+
return "ๅ
็ง ๅฟ่ๅ
็ง"
|
| 42 |
+
text_output = gr.Textbox(label="็งๅฎค")
|
| 43 |
+
|
| 44 |
+
with gr.Blocks(theme=theme) as demo:
|
| 45 |
+
gr.Markdown("ๅป็ๅ่ฏๅฉๆ")
|
| 46 |
+
gr.Image("bar.png")
|
| 47 |
+
with gr.Tab("ๅธธ่ง็้ฎ"):
|
| 48 |
+
with gr.Row():
|
| 49 |
+
btn1 = gr.Button(value="็ซ็ซ")
|
| 50 |
+
btn1.click(diagnosed_shennei, inputs=[], outputs=[text_output])
|
| 51 |
+
|
| 52 |
+
btn2 = gr.Button(value="ๅณๅฝ")
|
| 53 |
+
btn2.click(diagnosed_huxi, inputs=[], outputs=[text_output])
|
| 54 |
+
|
| 55 |
+
btn3 = gr.Button(value="ๆๅ")
|
| 56 |
+
btn3.click(diagnosed_huxi, inputs=[], outputs=[text_output])
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
with gr.Row():
|
| 60 |
+
btn4 = gr.Button(value="้ซ่กๅ")
|
| 61 |
+
btn4.click(diagnosed_xinnei, inputs=[], outputs=[text_output])
|
| 62 |
+
|
| 63 |
+
btn5 = gr.Button(value="ๅ็ง")
|
| 64 |
+
btn5.click(diagnosed_huxi, inputs=[], outputs=[text_output])
|
| 65 |
+
|
| 66 |
+
btn6 = gr.Button(value="่็")
|
| 67 |
+
btn6.click(diagnosed_xiaohua, inputs=[], outputs=[text_output])
|
| 68 |
+
|
| 69 |
+
with gr.Row():
|
| 70 |
+
text_output.render()
|
| 71 |
+
|
| 72 |
+
with gr.Tab("ๆๅจ้ฎๅ
ฅ"):
|
| 73 |
+
chatbot = gr.Chatbot()
|
| 74 |
+
msg = gr.Textbox()
|
| 75 |
+
clear = gr.ClearButton([msg, chatbot])
|
| 76 |
+
def respond(message, chat_history):
|
| 77 |
+
result = working_func(message)
|
| 78 |
+
bot_message = "็งๅฎค๏ผ" + result[0] + ',' + result[1] + '\n' + "ๅ็ญ๏ผ" + result[2]
|
| 79 |
+
chat_history.append((message, bot_message))
|
| 80 |
+
time.sleep(2)
|
| 81 |
+
return "", chat_history
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 85 |
+
|
| 86 |
+
with gr.Accordion("Open for More!"):
|
| 87 |
+
gr.Markdown("Look at me...")
|
| 88 |
+
|
| 89 |
+
#text_button.click(flip_text, inputs=text_input, outputs=text_output)
|
| 90 |
+
#image_button.click(flip_image, inputs=image_input, outputs=image_output)
|
| 91 |
+
|
| 92 |
+
demo.launch()
|