seawolf2357 commited on
Commit
9a34640
Β·
verified Β·
1 Parent(s): bc3813a

Update web.py

Browse files
Files changed (1) hide show
  1. web.py +19 -26
web.py CHANGED
@@ -1,33 +1,26 @@
1
  import gradio as gr
2
- import datetime
3
- import asyncio
4
 
5
- def update_live_message():
6
- """ ν˜„μž¬ μ‹œκ°„κ³Ό 'live' λ©”μ‹œμ§€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€. """
7
- current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
8
- return f"{current_time} - live"
9
-
10
- async def periodic_update(interface, interval=60):
11
- """ μ£Όμ–΄μ§„ μΈν„°νŽ˜μ΄μŠ€μ— 1λΆ„ κ°„κ²©μœΌλ‘œ μ—…λ°μ΄νŠΈλ₯Ό μ‹€ν–‰ν•©λ‹ˆλ‹€. """
12
- while True:
13
- live_message = update_live_message()
14
- interface.update(live_message)
15
- await asyncio.sleep(interval)
16
 
17
  def run_gradio():
18
- """ Gradio μ›Ή μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ„€μ •ν•˜κ³  μ‹€ν–‰ν•©λ‹ˆλ‹€. """
19
- live_block = gr.Textbox(label="Live Output", value="Starting...", elem_id="live_output")
20
-
21
- demo = gr.Blocks()
22
-
23
- with demo:
24
- gr.Markdown("## Live Server Output")
25
- live_block
26
-
27
- demo.launch(server_name="0.0.0.0", server_port=7860, inbrowser=True)
 
 
28
 
29
- # 비동기 μ—…λ°μ΄νŠΈ μž‘μ—… μ‹œμž‘
30
- asyncio.run(periodic_update(live_block))
31
 
32
  if __name__ == "__main__":
33
- run_gradio()
 
1
  import gradio as gr
2
+ import os
 
3
 
4
+ def chatbot(message):
5
+ # 여기에 챗봇 λ‘œμ§μ„ κ΅¬ν˜„ν•˜μ„Έμš”
6
+ return f"에코: {message}"
 
 
 
 
 
 
 
 
7
 
8
  def run_gradio():
9
+ with gr.Blocks() as demo:
10
+ chatbot = gr.Chatbot()
11
+ msg = gr.Textbox()
12
+ clear = gr.Button("Clear")
13
+
14
+ def respond(message, chat_history):
15
+ bot_message = chatbot(message)
16
+ chat_history.append((message, bot_message))
17
+ return "", chat_history
18
+
19
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
20
+ clear.click(lambda: None, None, chatbot, queue=False)
21
 
22
+ port = int(os.getenv('GRADIO_SERVER_PORT', 7860))
23
+ demo.launch(server_name="0.0.0.0", server_port=port, inbrowser=True)
24
 
25
  if __name__ == "__main__":
26
+ run_gradio()