Rooni commited on
Commit
849dbf1
·
1 Parent(s): 1029869

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ import requests
4
+ from io import BytesIO
5
+
6
+ # Функция для взаимодействия с моделью на Hugging Face
7
+ def process_image(image, prompt):
8
+ # Загрузка изображения
9
+ image_data = image.read()
10
+
11
+ # Отправка запроса на API Hugging Face
12
+ headers = {
13
+ "Authorization": f"Bearer YOUR_HUGGINGFACE_TOKEN" # Замените YOUR_HUGGINGFACE_TOKEN на ваш токен
14
+ }
15
+ data = {
16
+ "inputs": {
17
+ "image": image_data,
18
+ "prompt": prompt
19
+ }
20
+ }
21
+ response = requests.post("https://api-inference.huggingface.co/models/CrucibleAI/ControlNetMediaPipeFace", headers=headers, files=data)
22
+
23
+ # Обработка ответа
24
+ if response.status_code == 200:
25
+ # Преобразование ответа в изображение
26
+ image = Image.open(BytesIO(response.content))
27
+ return image
28
+ else:
29
+ # В случае ошибки возвращаем информацию об ошибке
30
+ return f"Error: {response.text}"
31
+
32
+ # Создание Gradio Blocks интерфейса
33
+ with gr.Blocks() as demo:
34
+ with gr.Row():
35
+ with gr.Column():
36
+ image_input = gr.Image(type="pil", label="Upload Image")
37
+ prompt_input = gr.Textbox(label="Enter Prompt")
38
+ with gr.Column():
39
+ output_image = gr.Image(type="pil", label="Output Image")
40
+
41
+ submit_button = gr.Button("Submit")
42
+ submit_button.click(fn=process_image, inputs=[image_input, prompt_input], outputs=output_image)
43
+
44
+ # Запуск интерфейса
45
+ demo.launch()