YaArtemNosenko commited on
Commit
4179d35
·
verified ·
1 Parent(s): c2dcd92

Update app.py

Browse files

[ADD] Add model_repo_id func

Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -7,15 +7,15 @@ from diffusers import DiffusionPipeline
7
  import torch
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
- model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
11
 
12
  if torch.cuda.is_available():
13
  torch_dtype = torch.float16
14
  else:
15
  torch_dtype = torch.float32
16
 
17
- pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
- pipe = pipe.to(device)
19
 
20
  MAX_SEED = np.iinfo(np.int32).max
21
  MAX_IMAGE_SIZE = 1024
@@ -23,6 +23,7 @@ MAX_IMAGE_SIZE = 1024
23
 
24
  # @spaces.GPU #[uncomment to use ZeroGPU]
25
  def infer(
 
26
  prompt,
27
  negative_prompt,
28
  seed,
@@ -35,7 +36,10 @@ def infer(
35
  ):
36
  if randomize_seed:
37
  seed = random.randint(0, MAX_SEED)
38
-
 
 
 
39
  generator = torch.Generator().manual_seed(seed)
40
 
41
  image = pipe(
@@ -69,6 +73,13 @@ with gr.Blocks(css=css) as demo:
69
  gr.Markdown(" # Text-to-Image Gradio Template")
70
 
71
  with gr.Row():
 
 
 
 
 
 
 
72
  prompt = gr.Text(
73
  label="Prompt",
74
  show_label=False,
@@ -138,6 +149,7 @@ with gr.Blocks(css=css) as demo:
138
  triggers=[run_button.click, prompt.submit],
139
  fn=infer,
140
  inputs=[
 
141
  prompt,
142
  negative_prompt,
143
  seed,
 
7
  import torch
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ # model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
11
 
12
  if torch.cuda.is_available():
13
  torch_dtype = torch.float16
14
  else:
15
  torch_dtype = torch.float32
16
 
17
+ # pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
+ # pipe = pipe.to(device)
19
 
20
  MAX_SEED = np.iinfo(np.int32).max
21
  MAX_IMAGE_SIZE = 1024
 
23
 
24
  # @spaces.GPU #[uncomment to use ZeroGPU]
25
  def infer(
26
+ model_repo_id,
27
  prompt,
28
  negative_prompt,
29
  seed,
 
36
  ):
37
  if randomize_seed:
38
  seed = random.randint(0, MAX_SEED)
39
+
40
+ pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
41
+ pipe = pipe.to(device)
42
+
43
  generator = torch.Generator().manual_seed(seed)
44
 
45
  image = pipe(
 
73
  gr.Markdown(" # Text-to-Image Gradio Template")
74
 
75
  with gr.Row():
76
+ model_repo_id = gr.Text(
77
+ label="model_repo_id",
78
+ show_label=False,
79
+ max_lines=1,
80
+ placeholder="Enter your model_repo_id",
81
+ container=False,
82
+ )
83
  prompt = gr.Text(
84
  label="Prompt",
85
  show_label=False,
 
149
  triggers=[run_button.click, prompt.submit],
150
  fn=infer,
151
  inputs=[
152
+ model_repo_id,
153
  prompt,
154
  negative_prompt,
155
  seed,