Update app.py
Browse files
app.py
CHANGED
@@ -6,20 +6,20 @@ import os
|
|
6 |
|
7 |
# Функция для взаимодействия с моделью на Hugging Face
|
8 |
def process_image(image, prompt):
|
9 |
-
#
|
10 |
-
|
|
|
|
|
11 |
|
12 |
# Отправка запроса на API Hugging Face
|
13 |
headers = {
|
14 |
-
"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"
|
15 |
}
|
16 |
-
|
17 |
-
"
|
18 |
-
|
19 |
-
"prompt": prompt
|
20 |
-
}
|
21 |
}
|
22 |
-
response = requests.post("https://api-inference.huggingface.co/models/CrucibleAI/ControlNetMediaPipeFace", headers=headers, files=
|
23 |
|
24 |
# Обработка ответа
|
25 |
if response.status_code == 200:
|
|
|
6 |
|
7 |
# Функция для взаимодействия с моделью на Hugging Face
|
8 |
def process_image(image, prompt):
|
9 |
+
# Преобразование объекта Image в байты
|
10 |
+
buffered = BytesIO()
|
11 |
+
image.save(buffered, format="JPEG")
|
12 |
+
image_data = buffered.getvalue()
|
13 |
|
14 |
# Отправка запроса на API Hugging Face
|
15 |
headers = {
|
16 |
+
"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"
|
17 |
}
|
18 |
+
files = {
|
19 |
+
"file": ("image.jpg", image_data, "image/jpeg"),
|
20 |
+
"data": (None, '{"inputs": {"prompt": ' + f'"{prompt}"' + '}}', "application/json"),
|
|
|
|
|
21 |
}
|
22 |
+
response = requests.post("https://api-inference.huggingface.co/models/CrucibleAI/ControlNetMediaPipeFace", headers=headers, files=files)
|
23 |
|
24 |
# Обработка ответа
|
25 |
if response.status_code == 200:
|