Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,27 @@
|
|
1 |
-
|
2 |
-
import
|
|
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
description = request.json.get('description')
|
15 |
-
if not description:
|
16 |
-
return jsonify({"error": "No description provided"}), 400
|
17 |
|
18 |
-
|
19 |
-
image_url = response['data'][0]['url'] # Пример получения URL изображения
|
20 |
-
|
21 |
-
return jsonify({"image_url": image_url})
|
22 |
-
|
23 |
-
if __name__ == '__main__':
|
24 |
-
app.run(debug=True)
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import requests
|
4 |
|
5 |
+
def generate_image(prompt, auth_key):
|
6 |
+
headers = {
|
7 |
+
"Authorization": f"Bearer {auth_key}",
|
8 |
+
"Content-Type": "application/json"
|
9 |
+
}
|
10 |
+
data = {
|
11 |
+
"description": prompt
|
12 |
+
}
|
13 |
+
response = requests.post("http://localhost:5000/generate-image", json=data, headers=headers)
|
14 |
+
if response.status_code != 200:
|
15 |
+
raise gr.Error(f"Ошибка при генерации изображения: {response.json().get('error')}")
|
16 |
+
return response.json()['image_url']
|
17 |
|
18 |
+
with gr.Blocks() as demo:
|
19 |
+
with gr.Row():
|
20 |
+
prompt_input = gr.Textbox(label="Описание изображения", lines=2)
|
21 |
+
auth_input = gr.Textbox(label="Ключ авторизации", type="password")
|
22 |
+
submit_button = gr.Button("Сгенерировать изображение")
|
23 |
+
image_output = gr.Image(label="Сгенерированное изображение")
|
24 |
|
25 |
+
submit_button.click(fn=generate_image, inputs=[prompt_input, auth_input], outputs=image_output)
|
|
|
|
|
|
|
26 |
|
27 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|