Reynold97 commited on
Commit
4ad9bee
1 Parent(s): 983031e
Files changed (3) hide show
  1. .env +1 -0
  2. app.py +63 -0
  3. requirements.txt +0 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ URL = https://api-dev.storyface.ai/api/images/swap_face_on_image
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ from PIL import Image
4
+ import io
5
+ from gradio.themes.base import Base
6
+ import os
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+ def process_images(face_image, model_image, watermark = False, vignette = False, quality = 100):
12
+ # Convertir las imágenes PIL a bytes
13
+ model_img_bytes = io.BytesIO()
14
+ model_image.save(model_img_bytes, format='PNG')
15
+ face_img_bytes = io.BytesIO()
16
+ face_image.save(face_img_bytes, format='PNG')
17
+
18
+ # Configurar los datos para la solicitud HTTP
19
+ url = os.getenv('URL')
20
+
21
+ files = [
22
+ ('images', ('face.png', face_img_bytes.getvalue(), 'image/jpeg')),
23
+ ('images', ('model.png', model_img_bytes.getvalue(), 'image/png'))
24
+ ]
25
+
26
+ data = {
27
+ 'watermark': 0,
28
+ 'quality': quality
29
+ }
30
+
31
+ response = requests.post(url, files=files, data=data)
32
+
33
+ if response.status_code == 200:
34
+ # Log the Content-Type to ensure it's an image
35
+ #print("Content-Type:", response.headers.get('Content-Type'))
36
+ #print(response.content)
37
+
38
+ # Attempt to open the response content as an image
39
+ try:
40
+ return Image.open(io.BytesIO(response.content))
41
+ except Exception as e:
42
+ print(f"Error opening image: {e}")
43
+ return None # Return None or handle the error as needed
44
+ else:
45
+ raise ValueError(f"Error in the request: Status Code {response.status_code}")
46
+
47
+
48
+ # Crear la interfaz de Gradio
49
+
50
+ iface = gr.Interface(
51
+ fn=process_images,
52
+ inputs=[
53
+ gr.Image(type="pil", label="Face Image"),
54
+ gr.Image(type="pil", label="Model Image")
55
+ ],
56
+ outputs=gr.Image(type="pil", label="Result Image"),
57
+ title="StoryFace Internal Tool",
58
+ description="<h2 style='text-align: center; font-size: 24px;'>Take a photo or upload a clear photo of your face, upload a photo of the model you want to see yourself in, and press the submit button..</h2>",
59
+ allow_flagging="never"
60
+ )
61
+
62
+ # Ejecutar la aplicación
63
+ iface.launch()
requirements.txt ADDED
Binary file (5.96 kB). View file