yash1161 commited on
Commit
05a46d3
·
1 Parent(s): 693bbb6

Updated requirements and modified script

Browse files
Files changed (3) hide show
  1. README.md +15 -10
  2. app.py +40 -19
  3. requirements.txt +81 -5
README.md CHANGED
@@ -1,13 +1,18 @@
1
  ---
2
- title: Stable Diffusion 2 1
3
- emoji: 🖼
4
- colorFrom: purple
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 5.0.1
8
- app_file: app.py
9
- pinned: false
10
- short_description: Public text-to-image AI model
 
 
 
 
 
 
 
11
  ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: "AI Image Generator"
3
+ emoji: 🎨
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: gradio
7
+ python_version: 3.10
8
+ sdk_version: 4.0
9
+ suggested_hardware: "cpu-basic"
10
+ app_file: "app.py"
11
+ models:
12
+ - prithivMLmods/SD3.5-Turbo-Realism-2.0-LoRA
13
+ - Purz/face-projection
14
+ tags:
15
+ - stable-diffusion
16
+ - text-to-image
17
+ pinned: true
18
  ---
 
 
app.py CHANGED
@@ -1,30 +1,51 @@
1
  import gradio as gr
 
 
2
  import torch
3
- from diffusers import StableDiffusionPipeline
4
 
5
- # Force using CPU
6
- device = "cpu"
7
 
8
- # Load the model on CPU
9
- pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float32)
10
- pipe.to(device)
11
 
12
- # Function to generate images
13
- def generate_image(prompt):
14
- with torch.no_grad(): # Disable gradient calculation
15
- image = pipe(prompt=prompt).images[0] # Generate image
16
- return image
17
 
18
- # Gradio UI
19
- with gr.Blocks() as demo:
20
- gr.Markdown("# Stable Diffusion 2.1 - Image Generator")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  with gr.Row():
23
- prompt = gr.Textbox(label="Enter Prompt", placeholder="Describe the image you want to generate")
24
- btn = gr.Button("Generate")
25
-
26
  output = gr.Image(label="Generated Image")
27
 
28
- btn.click(fn=generate_image, inputs=prompt, outputs=output)
 
29
 
30
- demo.launch(share=True) # Optional: Share link
 
1
  import gradio as gr
2
+ 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_image(text, selected_model):
15
+ stop_event.clear()
16
+
17
+ if selected_model == "Model 1 (Turbo Realism)":
18
+ model = model1
19
+ elif selected_model == "Model 2 (Face Projection)":
20
+ model = model2
21
+ else:
22
+ return "Invalid model selection."
23
+
24
+ if stop_event.is_set():
25
+ return "Image generation stopped by user."
26
+
27
+ return model(text)
28
+
29
+ def stop_generation():
30
+ """Stops the ongoing image generation by setting the stop_event flag."""
31
+ stop_event.set()
32
+ return "Generation stopped."
33
+
34
+ with gr.Blocks() as interface:
35
+ text_input = gr.Textbox(label="Type your prompt:", placeholder="Enter your imagination...")
36
+ model_selector = gr.Radio(
37
+ ["Model 1 (Turbo Realism)", "Model 2 (Face Projection)"],
38
+ label="Select Model",
39
+ value="Model 1 (Turbo Realism)"
40
+ )
41
 
42
  with gr.Row():
43
+ generate_button = gr.Button("Generate Image 🎨")
44
+ stop_button = gr.Button("Stop Image Generation")
45
+
46
  output = gr.Image(label="Generated Image")
47
 
48
+ generate_button.click(generate_image, inputs=[text_input, model_selector], outputs=output)
49
+ stop_button.click(stop_generation, inputs=[], outputs=output)
50
 
51
+ interface.launch()
requirements.txt CHANGED
@@ -1,5 +1,81 @@
1
- gradio
2
- diffusers
3
- torch
4
- torchvision
5
- transformers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ altair==5.5.0
3
+ annotated-types==0.7.0
4
+ anyio==4.9.0
5
+ attrs==25.3.0
6
+ certifi==2025.1.31
7
+ charset-normalizer==3.4.1
8
+ click==8.1.8
9
+ colorama==0.4.6
10
+ contourpy==1.3.1
11
+ cycler==0.12.1
12
+ diffusers==0.32.2
13
+ exceptiongroup==1.2.2
14
+ fastapi==0.115.12
15
+ ffmpy==0.5.0
16
+ filelock==3.18.0
17
+ fonttools==4.56.0
18
+ fsspec==2025.3.0
19
+ gradio==3.50.2
20
+ gradio_client==0.6.1
21
+ groovy==0.1.2
22
+ h11==0.14.0
23
+ httpcore==1.0.7
24
+ httpx==0.28.1
25
+ huggingface-hub==0.29.3
26
+ idna==3.10
27
+ importlib_metadata==8.6.1
28
+ importlib_resources==6.5.2
29
+ Jinja2==3.1.6
30
+ jsonschema==4.23.0
31
+ jsonschema-specifications==2024.10.1
32
+ kiwisolver==1.4.8
33
+ markdown-it-py==3.0.0
34
+ MarkupSafe==2.1.5
35
+ matplotlib==3.10.1
36
+ mdurl==0.1.2
37
+ mpmath==1.3.0
38
+ narwhals==1.32.0
39
+ networkx==3.4.2
40
+ numpy==1.26.4
41
+ orjson==3.10.16
42
+ packaging==24.2
43
+ pandas==2.2.3
44
+ pillow==10.4.0
45
+ pydantic==2.11.0
46
+ pydantic_core==2.33.0
47
+ pydub==0.25.1
48
+ Pygments==2.19.1
49
+ pyparsing==3.2.3
50
+ python-dateutil==2.9.0.post0
51
+ python-multipart==0.0.20
52
+ pytz==2025.2
53
+ PyYAML==6.0.2
54
+ referencing==0.36.2
55
+ regex==2024.11.6
56
+ requests==2.32.3
57
+ rich==13.9.4
58
+ rpds-py==0.24.0
59
+ ruff==0.11.2
60
+ safehttpx==0.1.6
61
+ safetensors==0.5.3
62
+ semantic-version==2.10.0
63
+ shellingham==1.5.4
64
+ six==1.17.0
65
+ sniffio==1.3.1
66
+ starlette==0.46.1
67
+ sympy==1.13.1
68
+ tokenizers==0.21.1
69
+ tomlkit==0.13.2
70
+ torch==2.6.0
71
+ torchvision==0.21.0
72
+ tqdm==4.67.1
73
+ transformers==4.50.2
74
+ typer==0.15.2
75
+ typing-inspection==0.4.0
76
+ typing_extensions==4.13.0
77
+ tzdata==2025.2
78
+ urllib3==2.3.0
79
+ uvicorn==0.34.0
80
+ websockets==11.0.3
81
+ zipp==3.21.0