Spaces:
Sleeping
Sleeping
Add application file
Browse files- app.py +62 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
+
import time
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
def add_text(history, text):
|
| 8 |
+
history = history + [(text, None)]
|
| 9 |
+
return history, ""
|
| 10 |
+
|
| 11 |
+
def bot(history):
|
| 12 |
+
response = infer(history[-1][0], history)
|
| 13 |
+
history[-1][1] = ""
|
| 14 |
+
|
| 15 |
+
for character in response:
|
| 16 |
+
history[-1][1] += character
|
| 17 |
+
time.sleep(0.05)
|
| 18 |
+
yield history
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def infer(wish, history):
|
| 22 |
+
result = "ความปรารถนาของคุณ จะเป็นจริงในเร็ววัน"
|
| 23 |
+
return result
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
css="""
|
| 27 |
+
#col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
title = """
|
| 31 |
+
<div style="text-align: center;max-width: 700px;">
|
| 32 |
+
<h1>เจ้าแม่กวนอิมให้พร</h1>
|
| 33 |
+
<h2>"บอกความปรารถนาของท่าน"</h2>
|
| 34 |
+
</div>
|
| 35 |
+
"""
|
| 36 |
+
version = """
|
| 37 |
+
<div style="text-align: center;max-width: 700px;">
|
| 38 |
+
<p style="text-align: left;">
|
| 39 |
+
version: 1.01
|
| 40 |
+
</p>
|
| 41 |
+
</div>
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
css = """
|
| 45 |
+
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
with gr.Blocks(css=css) as demo:
|
| 49 |
+
with gr.Column(elem_id="col-container"):
|
| 50 |
+
gr.HTML(title)
|
| 51 |
+
gr.HTML('<center><img src="https://huggingface.co/spaces/jingwora/Guan-Yin-Bless-You/resolve/main/guan-yin-01.jpg" alt="guan-yin-01.jpg" style="width:400px;"></center>')
|
| 52 |
+
|
| 53 |
+
wish = gr.Textbox(label="ความปรารถนา", placeholder="จงบอกความปรารถนาของท่าน")
|
| 54 |
+
submit_btn = gr.Button("ส่งความปรารถนา")
|
| 55 |
+
chatbot = gr.Chatbot([], elem_id="chatbot")
|
| 56 |
+
gr.HTML(version)
|
| 57 |
+
|
| 58 |
+
submit_btn.click(add_text, [chatbot, wish], [chatbot, wish]).then(
|
| 59 |
+
bot, chatbot, chatbot)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
demo.queue(concurrency_count=5, max_size=20).launch(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio==3.39.0
|