Bhagyashriss commited on
Commit
5bf3e73
·
verified ·
1 Parent(s): c7807f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
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("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
19
- pipe = pipe.to("cuda")
 
 
 
20
 
21
  def generate_image(prompt):
22
  if not prompt.isascii(): # If non-English
23
  prompt = translate_to_english(prompt)
24
 
25
- with torch.autocast("cuda"):
26
- image = pipe(prompt).images[0]
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()