Jonny001 commited on
Commit
de26b63
·
verified ·
1 Parent(s): c00cfff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -12
app.py CHANGED
@@ -3,14 +3,17 @@ import threading
3
  import os
4
  import torch
5
 
 
6
  os.environ["OMP_NUM_THREADS"] = str(os.cpu_count())
7
  torch.set_num_threads(os.cpu_count())
8
 
9
  model1 = gr.load("models/prithivMLmods/SD3.5-Turbo-Realism-2.0-LoRA")
10
  model2 = gr.load("models/Purz/face-projection")
11
 
 
12
  stop_event = threading.Event()
13
 
 
14
  def generate_images(text, selected_model):
15
  stop_event.clear()
16
 
@@ -27,38 +30,50 @@ def generate_images(text, selected_model):
27
  return ["Image generation stopped by user."] * 3
28
 
29
  modified_text = f"{text} variation {i+1}"
30
- result = model(modified_text)
31
- results.append(result)
 
 
 
 
32
 
33
  return results
34
 
35
  def stop_generation():
36
- """Stops the ongoing image generation by setting the stop_event flag."""
37
  stop_event.set()
38
  return ["Generation stopped."] * 3
39
 
40
- with gr.Blocks() as interface:#...
41
  gr.Markdown(
42
- "### ⚠ Sorry for the inconvenience. The Space is currently running on the CPU, which might affect performance. We appreciate your understanding."
43
  )
44
-
45
  text_input = gr.Textbox(label="Type here your imagination:", placeholder="Type your prompt...")
46
  model_selector = gr.Radio(
47
  ["Model 1 (Turbo Realism)", "Model 2 (Face Projection)"],
48
  label="Select Model",
49
  value="Model 1 (Turbo Realism)"
50
  )
51
-
52
  with gr.Row():
53
- generate_button = gr.Button("Generate 3 Images 🎨")
54
  stop_button = gr.Button("Stop Image Generation")
55
-
56
  with gr.Row():
57
  output1 = gr.Image(label="Generated Image 1")
58
  output2 = gr.Image(label="Generated Image 2")
59
  output3 = gr.Image(label="Generated Image 3")
60
-
61
- generate_button.click(generate_images, inputs=[text_input, model_selector], outputs=[output1, output2, output3])
62
- stop_button.click(stop_generation, inputs=[], outputs=[output1, output2, output3])
 
 
 
 
 
 
 
 
 
63
 
64
  interface.launch()
 
3
  import os
4
  import torch
5
 
6
+
7
  os.environ["OMP_NUM_THREADS"] = str(os.cpu_count())
8
  torch.set_num_threads(os.cpu_count())
9
 
10
  model1 = gr.load("models/prithivMLmods/SD3.5-Turbo-Realism-2.0-LoRA")
11
  model2 = gr.load("models/Purz/face-projection")
12
 
13
+
14
  stop_event = threading.Event()
15
 
16
+
17
  def generate_images(text, selected_model):
18
  stop_event.clear()
19
 
 
30
  return ["Image generation stopped by user."] * 3
31
 
32
  modified_text = f"{text} variation {i+1}"
33
+
34
+ try:
35
+ result = model.predict(modified_text)
36
+ results.append(result)
37
+ except Exception as e:
38
+ results.append(f"Error: {str(e)}")
39
 
40
  return results
41
 
42
  def stop_generation():
 
43
  stop_event.set()
44
  return ["Generation stopped."] * 3
45
 
46
+ with gr.Blocks() as interface:
47
  gr.Markdown(
48
+ "### ⚠ Sorry for the inconvenience. The model is currently running on the CPU, which might affect performance. We appreciate your understanding."
49
  )
50
+
51
  text_input = gr.Textbox(label="Type here your imagination:", placeholder="Type your prompt...")
52
  model_selector = gr.Radio(
53
  ["Model 1 (Turbo Realism)", "Model 2 (Face Projection)"],
54
  label="Select Model",
55
  value="Model 1 (Turbo Realism)"
56
  )
57
+
58
  with gr.Row():
59
+ generate_button = gr.Button("Generate 3 Images")
60
  stop_button = gr.Button("Stop Image Generation")
61
+
62
  with gr.Row():
63
  output1 = gr.Image(label="Generated Image 1")
64
  output2 = gr.Image(label="Generated Image 2")
65
  output3 = gr.Image(label="Generated Image 3")
66
+
67
+ generate_button.click(
68
+ generate_images,
69
+ inputs=[text_input, model_selector],
70
+ outputs=[output1, output2, output3]
71
+ )
72
+
73
+ stop_button.click(
74
+ stop_generation,
75
+ inputs=[],
76
+ outputs=[output1, output2, output3]
77
+ )
78
 
79
  interface.launch()