Jonny001 commited on
Commit
7a0d4a2
·
verified ·
1 Parent(s): 5736791

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -9,6 +9,7 @@ import base64
9
  import json
10
  import time
11
 
 
12
  class Prodia:
13
  def __init__(self, api_key=os.getenv("PRODIA_API_KEY"), base=None):
14
  self.base = base or "https://api.prodia.com/v1"
@@ -53,8 +54,10 @@ class Prodia:
53
 
54
  return response
55
 
 
56
  client = Prodia()
57
 
 
58
  def infer(source, target):
59
  if source_image is None or target_image is None:
60
  return
@@ -73,6 +76,7 @@ def infer(source, target):
73
 
74
  return res['imageUrl']
75
 
 
76
  def upload_image(file):
77
  files = {'file': open(file, 'rb')}
78
  img_id = requests.post(os.getenv("IMAGE_API_1"), files=files).json()['id']
@@ -87,15 +91,15 @@ def upload_image(file):
87
 
88
  return f"{os.getenv('IMAGE_API_1')}/{img_id}/{res.json()['attachments'][0]['filename']}"
89
 
 
90
  def image_to_base64(image: Image):
91
  buffered = BytesIO()
92
  image.save(buffered, format="PNG")
93
-
94
  img_str = base64.b64encode(buffered.getvalue())
95
-
96
  return img_str.decode('utf-8')
97
 
98
- with gr.Blocks() as demo:
 
99
  with gr.Column():
100
  gr.HTML("<h1><center>Face Swap</center></h1>")
101
 
@@ -107,12 +111,6 @@ with gr.Blocks() as demo:
107
  result = gr.Image()
108
  run_button = gr.Button("Swap Face", variant="primary")
109
 
110
- gr.Examples(
111
- fn=infer,
112
- inputs=[source_image, target_image],
113
- outputs=[result]
114
- )
115
-
116
  run_button.click(fn=infer, inputs=[source_image, target_image], outputs=[result])
117
 
118
  demo.queue(max_size=20, api_open=False).launch(show_api=False, max_threads=400)
 
9
  import json
10
  import time
11
 
12
+
13
  class Prodia:
14
  def __init__(self, api_key=os.getenv("PRODIA_API_KEY"), base=None):
15
  self.base = base or "https://api.prodia.com/v1"
 
54
 
55
  return response
56
 
57
+
58
  client = Prodia()
59
 
60
+
61
  def infer(source, target):
62
  if source_image is None or target_image is None:
63
  return
 
76
 
77
  return res['imageUrl']
78
 
79
+
80
  def upload_image(file):
81
  files = {'file': open(file, 'rb')}
82
  img_id = requests.post(os.getenv("IMAGE_API_1"), files=files).json()['id']
 
91
 
92
  return f"{os.getenv('IMAGE_API_1')}/{img_id}/{res.json()['attachments'][0]['filename']}"
93
 
94
+
95
  def image_to_base64(image: Image):
96
  buffered = BytesIO()
97
  image.save(buffered, format="PNG")
 
98
  img_str = base64.b64encode(buffered.getvalue())
 
99
  return img_str.decode('utf-8')
100
 
101
+
102
+ with gr.Blocks(description="Sorry for the inconvenience. The model is currently running on the CPU, which might affect performance. We appreciate your understanding.", theme="NoCrypt/miku") as demo:
103
  with gr.Column():
104
  gr.HTML("<h1><center>Face Swap</center></h1>")
105
 
 
111
  result = gr.Image()
112
  run_button = gr.Button("Swap Face", variant="primary")
113
 
 
 
 
 
 
 
114
  run_button.click(fn=infer, inputs=[source_image, target_image], outputs=[result])
115
 
116
  demo.queue(max_size=20, api_open=False).launch(show_api=False, max_threads=400)