ahmedghani commited on
Commit
a76fcef
β€’
1 Parent(s): 223afcb

added GPU implementation

Browse files
app.py CHANGED
@@ -1,8 +1,35 @@
 
1
  import gradio as gr
2
  from video_watermark_remover import *
3
  from video_converter import *
4
  from image_converter import *
5
  from image_watermark_remover import *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  css = """
8
  #remove_btn {
@@ -111,4 +138,12 @@ with demo:
111
 
112
  gr.Markdown("""## <center style="margin:20px;">Developed by Muhammad Ahmed<img src="https://avatars.githubusercontent.com/u/63394104?v=4" style="height:50px;width:50px;border-radius:50%;margin:5px;"></img></center>
113
  """)
 
 
 
 
 
 
 
 
114
  demo.launch(show_api=False)
 
1
+ import os
2
  import gradio as gr
3
  from video_watermark_remover import *
4
  from video_converter import *
5
  from image_converter import *
6
  from image_watermark_remover import *
7
+ from typing import List
8
+ from pydantic import BaseModel
9
+ from lama_cleaner.server import main
10
+
11
+ class FakeLamaArgs(BaseModel):
12
+ host: str = "0.0.0.0"
13
+ port: int = 5000
14
+ model: str = 'lama'
15
+ hf_access_token: str = ""
16
+ sd_disable_nsfw: bool = False
17
+ sd_cpu_textencoder: bool = True
18
+ sd_run_local: bool = False
19
+ sd_enable_xformers: bool = False
20
+ local_files_only: bool = False
21
+ cpu_offload: bool = False
22
+ device: str = "cuda"
23
+ gui: bool = False
24
+ gui_size: List[int] = [1000, 1000]
25
+ input: str = ''
26
+ disable_model_switch: bool = True
27
+ debug: bool = False
28
+ no_half: bool = False
29
+ disable_nsfw: bool = False
30
+ enable_xformers: bool = True
31
+ model_dir: str = None
32
+ output_dir: str = None
33
 
34
  css = """
35
  #remove_btn {
 
138
 
139
  gr.Markdown("""## <center style="margin:20px;">Developed by Muhammad Ahmed<img src="https://avatars.githubusercontent.com/u/63394104?v=4" style="height:50px;width:50px;border-radius:50%;margin:5px;"></img></center>
140
  """)
141
+
142
+ # Change the code according to the error
143
+ import threading
144
+
145
+ thread = threading.Thread(target=main, kwargs={'args': FakeLamaArgs()})
146
+ thread.daemon = True
147
+ thread.start()
148
+
149
  demo.launch(show_api=False)
image_watermark_remover.py CHANGED
@@ -52,7 +52,7 @@ def remove_image_watermark(input):
52
  'mask': ('mask.jpg', mask_data),
53
  }
54
 
55
- response = requests.post('https://ahmedghani-lama-cleaner-lama.hf.space/inpaint', data=form_data, files=files_data)
56
 
57
  if response.headers['Content-Type'] == 'image/jpeg' or response.headers['Content-Type'] == 'image/png':
58
  image = Image.open(io.BytesIO(response.content))
 
52
  'mask': ('mask.jpg', mask_data),
53
  }
54
 
55
+ response = requests.post('http://localhost:5000/inpaint', data=form_data, files=files_data)
56
 
57
  if response.headers['Content-Type'] == 'image/jpeg' or response.headers['Content-Type'] == 'image/png':
58
  image = Image.open(io.BytesIO(response.content))
requirements.txt CHANGED
@@ -3,4 +3,6 @@ ffmpeg-python
3
  moviepy
4
  pydub
5
  opencv-python
6
- pyheif
 
 
 
3
  moviepy
4
  pydub
5
  opencv-python
6
+ pyheif
7
+ lama-cleaner==0.33.0
8
+ xformers==0.0.16
video_watermark_remover.py CHANGED
@@ -55,7 +55,7 @@ def process_image(mask_data, image_path):
55
  'mask': ('mask.png', mask_data)
56
  }
57
 
58
- response = requests.post('https://ahmedghani-lama-cleaner-lama.hf.space/inpaint', data=form_data, files=files_data)
59
 
60
  if response.headers['Content-Type'] == 'image/jpeg' or response.headers['Content-Type'] == 'image/png':
61
  output_image_path = os.path.join('output_images', os.path.splitext(os.path.basename(image_path))[0] + '_inpainted' + os.path.splitext(image_path)[1])
 
55
  'mask': ('mask.png', mask_data)
56
  }
57
 
58
+ response = requests.post('http://localhost:5000/inpaint', data=form_data, files=files_data)
59
 
60
  if response.headers['Content-Type'] == 'image/jpeg' or response.headers['Content-Type'] == 'image/png':
61
  output_image_path = os.path.join('output_images', os.path.splitext(os.path.basename(image_path))[0] + '_inpainted' + os.path.splitext(image_path)[1])