seawolf2357 commited on
Commit
bfc8e91
β€’
1 Parent(s): 2b54a73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -23
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from flask import Flask, jsonify, request
2
  import threading
3
  import discord
4
  import logging
@@ -6,9 +6,6 @@ import os
6
  from huggingface_hub import InferenceClient
7
  import asyncio
8
 
9
- # ν”ŒλΌμŠ€ν¬ μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ„€μ •
10
- app = Flask(__name__)
11
-
12
  # λ‘œκΉ… μ„€μ •
13
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
14
 
@@ -98,32 +95,39 @@ async def generate_response(user_input):
98
  conversation_history.append({"role": "assistant", "content": full_response_text})
99
  return full_response_text
100
 
101
- # ν”ŒλΌμŠ€ν¬ 라우트 μ„€μ •
102
- @app.route('/')
103
- def index():
104
- return "λ””μŠ€μ½”λ“œ 봇이 μ‹€ν–‰ μ€‘μž…λ‹ˆλ‹€."
105
-
106
- @app.route('/status', methods=['GET'])
107
- def status():
108
- return jsonify({"status": "봇이 μ‹€ν–‰ μ€‘μž…λ‹ˆλ‹€."})
109
-
110
- @app.route('/send-message', methods=['POST'])
111
- def send_message():
112
- data = request.json
113
- channel_id = data.get('channel_id')
114
- message_content = data.get('message')
115
- channel = discord_client.get_channel(channel_id)
116
  if channel:
117
  asyncio.run_coroutine_threadsafe(channel.send(message_content), discord_client.loop)
118
- return jsonify({"status": "λ©”μ‹œμ§€ 전솑 μ™„λ£Œ"}), 200
119
  else:
120
- return jsonify({"error": "μœ νš¨ν•˜μ§€ μ•Šμ€ 채널 ID"}), 400
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
 
122
  def run_discord_bot():
123
  discord_client.run(os.getenv('DISCORD_TOKEN'))
124
 
125
- # λ””μŠ€μ½”λ“œ 봇을 λ³„λ„μ˜ μŠ€λ ˆλ“œμ—μ„œ μ‹€ν–‰
126
  if __name__ == "__main__":
127
  discord_client = MyClient(intents=intents)
128
  threading.Thread(target=run_discord_bot).start() # 봇 μ‹€ν–‰
129
- app.run(host='0.0.0.0', port=5000) # ν”ŒλΌμŠ€ν¬ μ„œλ²„ μ‹€ν–‰
 
1
+ import gradio as gr
2
  import threading
3
  import discord
4
  import logging
 
6
  from huggingface_hub import InferenceClient
7
  import asyncio
8
 
 
 
 
9
  # λ‘œκΉ… μ„€μ •
10
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
11
 
 
95
  conversation_history.append({"role": "assistant", "content": full_response_text})
96
  return full_response_text
97
 
98
+ # Gradio ν•¨μˆ˜ μ •μ˜
99
+ def send_message_to_discord(channel_id, message_content):
100
+ channel = discord_client.get_channel(int(channel_id))
 
 
 
 
 
 
 
 
 
 
 
 
101
  if channel:
102
  asyncio.run_coroutine_threadsafe(channel.send(message_content), discord_client.loop)
103
+ return "λ©”μ‹œμ§€ 전솑 μ™„λ£Œ"
104
  else:
105
+ return "μœ νš¨ν•˜μ§€ μ•Šμ€ 채널 ID"
106
+
107
+ # Gradio μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
108
+ with gr.Blocks() as demo:
109
+ with gr.Row():
110
+ gr.Markdown("## λ””μŠ€μ½”λ“œ 봇 μƒνƒœ 및 λ©”μ‹œμ§€ 전솑")
111
+ with gr.Row():
112
+ status_button = gr.Button("μƒνƒœ 확인")
113
+ status_output = gr.Textbox(label="봇 μƒνƒœ", placeholder="μƒνƒœ λ²„νŠΌμ„ ν΄λ¦­ν•˜μ„Έμš”.", interactive=False)
114
+ with gr.Row():
115
+ channel_id_input = gr.Textbox(label="채널 ID", placeholder="λ””μŠ€μ½”λ“œ 채널 IDλ₯Ό μž…λ ₯ν•˜μ„Έμš”.")
116
+ message_input = gr.Textbox(label="λ©”μ‹œμ§€ λ‚΄μš©", placeholder="전솑할 λ©”μ‹œμ§€ λ‚΄μš©μ„ μž…λ ₯ν•˜μ„Έμš”.")
117
+ send_button = gr.Button("λ©”μ‹œμ§€ 전솑")
118
+ send_output = gr.Textbox(label="λ©”μ‹œμ§€ 전솑 κ²°κ³Ό", placeholder="λ©”μ‹œμ§€ 전솑 κ²°κ³Όκ°€ 여기에 ν‘œμ‹œλ©λ‹ˆλ‹€.", interactive=False)
119
+
120
+ def check_status():
121
+ return "봇이 μ‹€ν–‰ μ€‘μž…λ‹ˆλ‹€."
122
+
123
+ status_button.click(fn=check_status, outputs=status_output)
124
+ send_button.click(fn=send_message_to_discord, inputs=[channel_id_input, message_input], outputs=send_output)
125
 
126
+ # λ””μŠ€μ½”λ“œ 봇을 λ³„λ„μ˜ μŠ€λ ˆλ“œμ—μ„œ μ‹€ν–‰
127
  def run_discord_bot():
128
  discord_client.run(os.getenv('DISCORD_TOKEN'))
129
 
 
130
  if __name__ == "__main__":
131
  discord_client = MyClient(intents=intents)
132
  threading.Thread(target=run_discord_bot).start() # 봇 μ‹€ν–‰
133
+ demo.launch(server_name="0.0.0.0", server_port=5000) # Gradio μ„œλ²„ μ‹€ν–‰