Spaces:
Paused
Paused
commit
Browse files
app.py
CHANGED
|
@@ -25,7 +25,7 @@ from lxml.html import fromstring
|
|
| 25 |
from diffusers.utils import export_to_video, load_image
|
| 26 |
from huggingface_hub import hf_hub_download
|
| 27 |
from safetensors.torch import load_file, save_file
|
| 28 |
-
from diffusers import FluxPipeline,
|
| 29 |
from PIL import Image, ImageDraw, ImageFont
|
| 30 |
|
| 31 |
# logging
|
|
@@ -126,65 +126,16 @@ function custom(){
|
|
| 126 |
|
| 127 |
image_pipe = FluxPipeline.from_pretrained(base, torch_dtype=torch.float32).to(device)
|
| 128 |
|
| 129 |
-
|
| 130 |
-
"
|
| 131 |
-
|
| 132 |
-
video_pipe = HunyuanVideoPipeline.from_pretrained(
|
| 133 |
-
"hunyuanvideo-community/HunyuanVideo", transformer=transformer, torch_dtype=torch.float16
|
| 134 |
).to(device)
|
| 135 |
|
| 136 |
video_pipe.vae.enable_tiling()
|
| 137 |
video_pipe.vae.enable_slicing()
|
| 138 |
-
video_pipe.enable_model_cpu_offload()
|
| 139 |
|
| 140 |
# functionality
|
| 141 |
|
| 142 |
-
def run(cmd):
|
| 143 |
-
return str(subprocess.run(cmd, shell=True, capture_output=True, env=None).stdout)
|
| 144 |
-
|
| 145 |
-
def xpath_finder(str,pattern):
|
| 146 |
-
try:
|
| 147 |
-
return ""+fromstring(str).xpath(pattern)[0].text_content().lower().strip()
|
| 148 |
-
except:
|
| 149 |
-
return ""
|
| 150 |
-
|
| 151 |
-
def translate(text,lang):
|
| 152 |
-
if text == None or lang == None:
|
| 153 |
-
return ""
|
| 154 |
-
text = re.sub(f'[{punctuation}]', '', re.sub('[ ]+', ' ', text)).lower().strip()
|
| 155 |
-
lang = re.sub(f'[{punctuation}]', '', re.sub('[ ]+', ' ', lang)).lower().strip()
|
| 156 |
-
if text == "" or lang == "":
|
| 157 |
-
return ""
|
| 158 |
-
if len(text) > 38:
|
| 159 |
-
raise Exception("Translation Error: Too long text!")
|
| 160 |
-
user_agents = [
|
| 161 |
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
| 162 |
-
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
| 163 |
-
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
| 164 |
-
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15',
|
| 165 |
-
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
|
| 166 |
-
]
|
| 167 |
-
text = text.strip()
|
| 168 |
-
query_text = f'Please translate {text}, into {lang}'
|
| 169 |
-
url = f'https://www.google.com/search?q={query_text}'
|
| 170 |
-
print(url)
|
| 171 |
-
content = str(requests.get(
|
| 172 |
-
url = url,
|
| 173 |
-
headers = {
|
| 174 |
-
'User-Agent': random.choice(user_agents)
|
| 175 |
-
}
|
| 176 |
-
).content)
|
| 177 |
-
translated = text
|
| 178 |
-
src_lang = xpath_finder(content,'//*[@class="source-language"]')
|
| 179 |
-
trgt_lang = xpath_finder(content,'//*[@class="target-language"]')
|
| 180 |
-
src_text = xpath_finder(content,'//*[@id="tw-source-text"]/*')
|
| 181 |
-
trgt_text = xpath_finder(content,'//*[@id="tw-target-text"]/*')
|
| 182 |
-
if trgt_lang == lang:
|
| 183 |
-
translated = trgt_text
|
| 184 |
-
ret = re.sub(f'[{punctuation}]', '', re.sub('[ ]+', ' ', translated)).lower().strip()
|
| 185 |
-
print(ret)
|
| 186 |
-
return ret
|
| 187 |
-
|
| 188 |
def generate_random_string(length):
|
| 189 |
characters = str(ascii_letters + digits)
|
| 190 |
return ''.join(random.choice(characters) for _ in range(length))
|
|
|
|
| 25 |
from diffusers.utils import export_to_video, load_image
|
| 26 |
from huggingface_hub import hf_hub_download
|
| 27 |
from safetensors.torch import load_file, save_file
|
| 28 |
+
from diffusers import FluxPipeline, CogVideoXImageToVideoPipeline
|
| 29 |
from PIL import Image, ImageDraw, ImageFont
|
| 30 |
|
| 31 |
# logging
|
|
|
|
| 126 |
|
| 127 |
image_pipe = FluxPipeline.from_pretrained(base, torch_dtype=torch.float32).to(device)
|
| 128 |
|
| 129 |
+
video_pipe = CogVideoXImageToVideoPipeline.from_pretrained(
|
| 130 |
+
"THUDM/CogVideoX-5b-I2V",
|
| 131 |
+
torch_dtype=torch.bfloat16
|
|
|
|
|
|
|
| 132 |
).to(device)
|
| 133 |
|
| 134 |
video_pipe.vae.enable_tiling()
|
| 135 |
video_pipe.vae.enable_slicing()
|
|
|
|
| 136 |
|
| 137 |
# functionality
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
def generate_random_string(length):
|
| 140 |
characters = str(ascii_letters + digits)
|
| 141 |
return ''.join(random.choice(characters) for _ in range(length))
|