amirkhanbloch commited on
Commit
038b110
·
verified ·
1 Parent(s): dff854b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -1,5 +1,9 @@
1
  import os
2
  from huggingface_hub import login
 
 
 
 
3
 
4
  # Get Hugging Face token from environment variables
5
  hf_token = os.getenv("HF_API_TOKEN")
@@ -9,3 +13,31 @@ if hf_token:
9
  print("lgin sucessfull")
10
  else:
11
  raise ValueError("Hugging Face token is missing. Please set it in the environment variables.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  from huggingface_hub import login
3
+ import torch
4
+ import gradio as gr
5
+ from diffusers import StableDiffusion3Pipeline
6
+
7
 
8
  # Get Hugging Face token from environment variables
9
  hf_token = os.getenv("HF_API_TOKEN")
 
13
  print("lgin sucessfull")
14
  else:
15
  raise ValueError("Hugging Face token is missing. Please set it in the environment variables.")
16
+ def image_generator(prompt):
17
+ device = "cuda" if torch.cuda.is_available() else "cpu"
18
+ pipeline = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers",
19
+ torch_dtype=torch.float16 if device == "cuda" else torch.float32,
20
+ text_encoder_3=None,
21
+ tokenizer_3 = None)
22
+ #pipeline.enable_model_cpu_offload()
23
+ pipeline.to(device)
24
+
25
+ image = pipeline(
26
+ prompt=prompt,
27
+ negative_prompt="blurred, ugly, watermark, low, resolution, blurry",
28
+ num_inference_steps=40,
29
+ height=1024,
30
+ width=1024,
31
+ guidance_scale=9.0
32
+ ).images[0]
33
+
34
+ return image
35
+
36
+ interface = gr.Interface(
37
+ fn=image_generator,
38
+ inputs=gr.Textbox(lines=2, placeholder = "Enter your prompt..."),
39
+ outputs=gr.Image(type = "pil"),
40
+ title = "Image Generator App",
41
+ description = "This is a simple image generator app using HuggingFace's Stable Diffusion 3 model.")
42
+ interface.launch()
43
+ print(interface)