Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -14,16 +14,19 @@ def translate_to_english(text):
|
|
14 |
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
15 |
return translated_text
|
16 |
|
17 |
-
# Load Stable Diffusion
|
18 |
-
pipe = StableDiffusionPipeline.from_pretrained(
|
19 |
-
|
|
|
|
|
|
|
20 |
|
21 |
def generate_image(prompt):
|
22 |
if not prompt.isascii(): # If non-English
|
23 |
prompt = translate_to_english(prompt)
|
24 |
|
25 |
-
|
26 |
-
|
27 |
return image
|
28 |
|
29 |
# Gradio Interface
|
@@ -31,8 +34,8 @@ app = gr.Interface(
|
|
31 |
fn=generate_image,
|
32 |
inputs=gr.Textbox(label="Enter prompt (any language)"),
|
33 |
outputs=gr.Image(label="Generated Image"),
|
34 |
-
title="🌍 Multilingual Text-to-Image Generator",
|
35 |
-
description="Type in **English, हिंदी, मराठी, Deutsch, etc.** and get an image!"
|
36 |
)
|
37 |
|
38 |
app.launch()
|
|
|
14 |
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
15 |
return translated_text
|
16 |
|
17 |
+
# Load Stable Diffusion on CPU
|
18 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
19 |
+
"runwayml/stable-diffusion-v1-5",
|
20 |
+
torch_dtype=torch.float32 # Use float32 for CPU
|
21 |
+
)
|
22 |
+
pipe = pipe.to("cpu") # Force CPU mode
|
23 |
|
24 |
def generate_image(prompt):
|
25 |
if not prompt.isascii(): # If non-English
|
26 |
prompt = translate_to_english(prompt)
|
27 |
|
28 |
+
# Generate image (no autocast on CPU)
|
29 |
+
image = pipe(prompt).images[0]
|
30 |
return image
|
31 |
|
32 |
# Gradio Interface
|
|
|
34 |
fn=generate_image,
|
35 |
inputs=gr.Textbox(label="Enter prompt (any language)"),
|
36 |
outputs=gr.Image(label="Generated Image"),
|
37 |
+
title="🌍 Multilingual Text-to-Image Generator (CPU Mode)",
|
38 |
+
description="Type in **English, हिंदी, मराठी, Deutsch, etc.** and get an image! (Slower on CPU)"
|
39 |
)
|
40 |
|
41 |
app.launch()
|