Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,7 @@
|
|
1 |
import discord
|
2 |
import logging
|
3 |
import os
|
4 |
-
import
|
5 |
-
import subprocess
|
6 |
-
import threading
|
7 |
-
import gradio as gr
|
8 |
from gradio_client import Client
|
9 |
|
10 |
# λ‘κΉ
μ€μ
|
@@ -14,21 +11,8 @@ logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(nam
|
|
14 |
intents = discord.Intents.default()
|
15 |
intents.message_content = True
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
# μ΄λ―Έμ§ μμ± ν¨μ
|
21 |
-
def generate_image(prompt):
|
22 |
-
# μ€μ μ΄λ―Έμ§ μμ± λ‘μ§μ ꡬνν©λλ€.
|
23 |
-
# μμλ‘, μ¬κΈ°μλ λ¨μν promptλ₯Ό μ΄λ―Έμ§μ νμνλ κ°μ§ μ΄λ―Έμ§ μμ±μ ν κ²μ
λλ€.
|
24 |
-
return f"Image generated with prompt: {prompt}"
|
25 |
-
|
26 |
-
# Gradio μΈν°νμ΄μ€ μ€μ
|
27 |
-
iface = gr.Interface(fn=generate_image, inputs="text", outputs="image")
|
28 |
-
|
29 |
-
# Gradio μΈν°νμ΄μ€ μ€ν ν¨μ
|
30 |
-
def run_gradio():
|
31 |
-
iface.launch(show_error=True)
|
32 |
|
33 |
# λμ€μ½λ λ΄ ν΄λμ€
|
34 |
class MyClient(discord.Client):
|
@@ -38,8 +22,7 @@ class MyClient(discord.Client):
|
|
38 |
|
39 |
async def on_ready(self):
|
40 |
logging.info(f'{self.user}λ‘ λ‘κ·ΈμΈλμμ΅λλ€!')
|
41 |
-
|
42 |
-
logging.info("web.py μλ²κ° μμλμμ΅λλ€.")
|
43 |
channel = self.get_channel(int(os.getenv("DISCORD_CHANNEL_ID", "123456789012345678")))
|
44 |
await channel.send("μ λ μ΄λ―Έμ§ μμ±μ μνν μ μμΌλ©°, μμ±λ μ΄λ―Έμ§μ λν μ€λͺ
μ νκΈλ‘ μ 곡νκ³ μνΈ λνλ₯Ό ν μ μμ΅λλ€. '!image <ν둬ννΈ>'λ₯Ό μ¬μ©νμ¬ μ΄λ―Έμ§λ₯Ό μμ²νμΈμ.")
|
45 |
|
@@ -57,9 +40,10 @@ class MyClient(discord.Client):
|
|
57 |
user_id = message.author.id
|
58 |
await message.channel.send(
|
59 |
f"<@{user_id}> λμ΄ μμ²νμ μ΄λ―Έμ§μ
λλ€.",
|
60 |
-
file=discord.File(image_path
|
61 |
)
|
62 |
-
|
|
|
63 |
except Exception as e:
|
64 |
logging.error(f'μ΄λ―Έμ§ μμ± μ€ μ€λ₯ λ°μ: {e}')
|
65 |
await message.channel.send("μ΄λ―Έμ§ μμ± μ€ μ€λ₯κ° λ°μνμ΅λλ€. λμ€μ λ€μ μλν΄ μ£ΌμΈμ.")
|
@@ -70,8 +54,10 @@ class MyClient(discord.Client):
|
|
70 |
if not prompt:
|
71 |
raise ValueError("Prompt is empty or None")
|
72 |
|
|
|
|
|
73 |
try:
|
74 |
-
result =
|
75 |
prompt=prompt,
|
76 |
seed=123,
|
77 |
randomize_seed=False,
|
@@ -81,20 +67,19 @@ class MyClient(discord.Client):
|
|
81 |
num_inference_steps=28,
|
82 |
api_name="/infer_t2i"
|
83 |
)
|
84 |
-
logging.debug(f"API
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
else:
|
91 |
-
raise RuntimeError("μ΄λ―Έμ§ μμ± μ€ν¨: κ²°κ³Όκ° λΉμ΄ μκ±°λ κ²½λ‘κ° ν¬ν¨λμ§ μμμ΅λλ€.")
|
92 |
except Exception as e:
|
93 |
-
logging.error(f'
|
94 |
-
raise RuntimeError(f"
|
95 |
|
96 |
-
async def initiate_conversation(prompt,
|
97 |
logging.debug(f'λν μμ μ€: {prompt}')
|
|
|
98 |
description = "μμ±λ μ΄λ―Έμ§μ
λλ€."
|
99 |
logging.debug(f'μ΄λ―Έμ§ μ€λͺ
: {description}')
|
100 |
|
@@ -102,6 +87,7 @@ async def initiate_conversation(prompt, image_path, message):
|
|
102 |
await continue_conversation(prompt, message)
|
103 |
|
104 |
async def continue_conversation(prompt, message):
|
|
|
105 |
logging.debug(f'λν μ§μ μ€: {prompt}')
|
106 |
# κ³μ λν λ΄μ©μ λ°μ μνΈμμ©νλλ‘ κ΅¬ν
|
107 |
|
@@ -109,10 +95,4 @@ async def continue_conversation(prompt, message):
|
|
109 |
if __name__ == "__main__":
|
110 |
discord_token = os.getenv('DISCORD_TOKEN')
|
111 |
discord_client = MyClient(intents=intents)
|
112 |
-
discord_client.run(discord_token)
|
113 |
-
|
114 |
-
# Gradio μΈν°νμ΄μ€ μ€μ
|
115 |
-
iface = gr.Interface(fn=my_model_function, inputs="text", outputs="image")
|
116 |
-
|
117 |
-
# μΈν°νμ΄μ€ μ€ν, μ€λ₯ 보μ¬μ£Όλ μ΅μ
νμ±ν
|
118 |
-
iface.launch(show_error=True)
|
|
|
1 |
import discord
|
2 |
import logging
|
3 |
import os
|
4 |
+
from io import BytesIO
|
|
|
|
|
|
|
5 |
from gradio_client import Client
|
6 |
|
7 |
# λ‘κΉ
μ€μ
|
|
|
11 |
intents = discord.Intents.default()
|
12 |
intents.message_content = True
|
13 |
|
14 |
+
# API ν΄λΌμ΄μΈνΈ μ€μ
|
15 |
+
api_client = Client("http://211.233.58.202:7960/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# λμ€μ½λ λ΄ ν΄λμ€
|
18 |
class MyClient(discord.Client):
|
|
|
22 |
|
23 |
async def on_ready(self):
|
24 |
logging.info(f'{self.user}λ‘ λ‘κ·ΈμΈλμμ΅λλ€!')
|
25 |
+
# μνΈ λν κΈ°λ₯ μλ¦Ό
|
|
|
26 |
channel = self.get_channel(int(os.getenv("DISCORD_CHANNEL_ID", "123456789012345678")))
|
27 |
await channel.send("μ λ μ΄λ―Έμ§ μμ±μ μνν μ μμΌλ©°, μμ±λ μ΄λ―Έμ§μ λν μ€λͺ
μ νκΈλ‘ μ 곡νκ³ μνΈ λνλ₯Ό ν μ μμ΅λλ€. '!image <ν둬ννΈ>'λ₯Ό μ¬μ©νμ¬ μ΄λ―Έμ§λ₯Ό μμ²νμΈμ.")
|
28 |
|
|
|
40 |
user_id = message.author.id
|
41 |
await message.channel.send(
|
42 |
f"<@{user_id}> λμ΄ μμ²νμ μ΄λ―Έμ§μ
λλ€.",
|
43 |
+
file=discord.File(image_path)
|
44 |
)
|
45 |
+
# μ΄λ―Έμ§ μμ± ν μ€λͺ
μ 곡 λ° λν
|
46 |
+
await initiate_conversation(prompt, message)
|
47 |
except Exception as e:
|
48 |
logging.error(f'μ΄λ―Έμ§ μμ± μ€ μ€λ₯ λ°μ: {e}')
|
49 |
await message.channel.send("μ΄λ―Έμ§ μμ± μ€ μ€λ₯κ° λ°μνμ΅λλ€. λμ€μ λ€μ μλν΄ μ£ΌμΈμ.")
|
|
|
54 |
if not prompt:
|
55 |
raise ValueError("Prompt is empty or None")
|
56 |
|
57 |
+
logging.debug(f"Sending request to API with prompt: {prompt}")
|
58 |
+
|
59 |
try:
|
60 |
+
result = api_client.predict(
|
61 |
prompt=prompt,
|
62 |
seed=123,
|
63 |
randomize_seed=False,
|
|
|
67 |
num_inference_steps=28,
|
68 |
api_name="/infer_t2i"
|
69 |
)
|
70 |
+
logging.debug(f"API response received: {result}")
|
71 |
+
|
72 |
+
# API μλ΅μμ μ΄λ―Έμ§ νμΌ κ²½λ‘ μΆμΆ
|
73 |
+
image_path = result[0] # API μλ΅ κ΅¬μ‘°μ λ°λΌ μ‘°μ μ΄ νμν μ μμ΅λλ€
|
74 |
+
|
75 |
+
return image_path
|
|
|
|
|
76 |
except Exception as e:
|
77 |
+
logging.error(f'API μμ² μ€ μ€λ₯ λ°μ: {e}')
|
78 |
+
raise RuntimeError(f"API μμ² μ€ μ€λ₯ λ°μ: {str(e)}")
|
79 |
|
80 |
+
async def initiate_conversation(prompt, message):
|
81 |
logging.debug(f'λν μμ μ€: {prompt}')
|
82 |
+
# μ΄λ―Έμ§ μ€λͺ
μ νκΈλ‘ μμ±
|
83 |
description = "μμ±λ μ΄λ―Έμ§μ
λλ€."
|
84 |
logging.debug(f'μ΄λ―Έμ§ μ€λͺ
: {description}')
|
85 |
|
|
|
87 |
await continue_conversation(prompt, message)
|
88 |
|
89 |
async def continue_conversation(prompt, message):
|
90 |
+
# λν μ§μ κΈ°λ₯
|
91 |
logging.debug(f'λν μ§μ μ€: {prompt}')
|
92 |
# κ³μ λν λ΄μ©μ λ°μ μνΈμμ©νλλ‘ κ΅¬ν
|
93 |
|
|
|
95 |
if __name__ == "__main__":
|
96 |
discord_token = os.getenv('DISCORD_TOKEN')
|
97 |
discord_client = MyClient(intents=intents)
|
98 |
+
discord_client.run(discord_token)
|
|
|
|
|
|
|
|
|
|
|
|