Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -21,10 +21,6 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
21 |
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
22 |
headers = {"Authorization": "Bearer " + HF_TOKEN}
|
23 |
|
24 |
-
def query(payload):
|
25 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
26 |
-
return response.content
|
27 |
-
|
28 |
def ask(input_text):
|
29 |
api_url = "https://somerandomapifor-disorc-cause-i-need-it.onrender.com/qa"
|
30 |
params = {'question': input_text}
|
@@ -73,16 +69,24 @@ async def ai(ctx, *, input_text: str):
|
|
73 |
# Reply with the embed
|
74 |
await ctx.send(result)
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
@bot.command()
|
77 |
async def img(ctx, *, prompt: str):
|
78 |
-
|
79 |
-
|
80 |
-
async with ctx.typing():
|
81 |
-
image_data = query(prompt)
|
82 |
-
|
83 |
-
# Send the image as a file
|
84 |
-
await ctx.send(file=discord.File(image_data, filename="generated_image.png"))
|
85 |
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
|
88 |
@bot.command()
|
|
|
21 |
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
22 |
headers = {"Authorization": "Bearer " + HF_TOKEN}
|
23 |
|
|
|
|
|
|
|
|
|
24 |
def ask(input_text):
|
25 |
api_url = "https://somerandomapifor-disorc-cause-i-need-it.onrender.com/qa"
|
26 |
params = {'question': input_text}
|
|
|
69 |
# Reply with the embed
|
70 |
await ctx.send(result)
|
71 |
|
72 |
+
def query(prompt):
|
73 |
+
payload = {
|
74 |
+
"prompt": prompt,
|
75 |
+
"num_return_sequences": 1
|
76 |
+
}
|
77 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
78 |
+
return response.content
|
79 |
+
|
80 |
@bot.command()
|
81 |
async def img(ctx, *, prompt: str):
|
82 |
+
# Query the API to generate the image
|
83 |
+
image_data = query(prompt)
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
+
# Encode image data as base64
|
86 |
+
image_b64 = base64.b64encode(image_data).decode('utf-8')
|
87 |
+
|
88 |
+
# Send the image as a file
|
89 |
+
await ctx.send(file=discord.File(base64.b64decode(image_b64), filename="generated_image.png"))
|
90 |
|
91 |
|
92 |
@bot.command()
|