seawolf2357
commited on
Commit
β’
bfc8e91
1
Parent(s):
2b54a73
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
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 |
-
|
103 |
-
|
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
|
119 |
else:
|
120 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
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 μλ² μ€ν
|