Spaces:
Sleeping
Sleeping
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,16 @@
|
|
1 |
-
import gradio as gr
|
2 |
import spaces
|
3 |
-
|
|
|
4 |
import numpy as np
|
5 |
import random
|
6 |
from diffusers import StableDiffusionPipeline as DiffusionPipeline
|
7 |
import torch
|
8 |
-
from pathos.multiprocessing import ProcessingPool as ProcessPoolExecutor
|
|
|
|
|
9 |
|
10 |
-
pool = ProcessPoolExecutor(100)
|
11 |
-
pool.__enter__()
|
12 |
|
13 |
model_id = "runwayml/stable-diffusion-v1-5"
|
14 |
|
@@ -22,13 +24,21 @@ else:
|
|
22 |
pipe = DiffusionPipeline.from_pretrained(model_id, use_safetensors=True)
|
23 |
pipe = pipe.to(device)
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
def infer(prompt):
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
ret = file.name
|
31 |
-
return ret
|
32 |
|
33 |
css="""
|
34 |
#col-container {
|
|
|
|
|
1 |
import spaces
|
2 |
+
import gradio as gr
|
3 |
+
#from tempfile import NamedTemporaryFile
|
4 |
import numpy as np
|
5 |
import random
|
6 |
from diffusers import StableDiffusionPipeline as DiffusionPipeline
|
7 |
import torch
|
8 |
+
#from pathos.multiprocessing import ProcessingPool as ProcessPoolExecutor
|
9 |
+
import requests
|
10 |
+
from lxml.html.soupparser import fromstring
|
11 |
|
12 |
+
#pool = ProcessPoolExecutor(100)
|
13 |
+
#pool.__enter__()
|
14 |
|
15 |
model_id = "runwayml/stable-diffusion-v1-5"
|
16 |
|
|
|
24 |
pipe = DiffusionPipeline.from_pretrained(model_id, use_safetensors=True)
|
25 |
pipe = pipe.to(device)
|
26 |
|
27 |
+
def he_to_en(prompt):
|
28 |
+
html_str = requests.get( url = "https://translate.google.com", params = {"sl": "iw", "tl": "en", "op": "translate", "text": prompt} ).text()
|
29 |
+
tree = fromstring(html_str)
|
30 |
+
english = tree.xpath('span[lang="en"]/span/span/text()')[0]
|
31 |
+
return english
|
32 |
+
|
33 |
+
def generate_random_string(length):
|
34 |
+
characters = string.ascii_letters + string.digits
|
35 |
+
return ''.join(random.choice(characters) for _ in range(length))
|
36 |
+
|
37 |
+
@spaces.GPU(25)
|
38 |
def infer(prompt):
|
39 |
+
name = generate_random_string(12)+".png"
|
40 |
+
image = pipe(he_to_en(prompt)).images[0].save(name)
|
41 |
+
return name
|
|
|
|
|
42 |
|
43 |
css="""
|
44 |
#col-container {
|