Hassan501 commited on
Commit
dffb3b3
·
verified ·
1 Parent(s): dc486e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -9
app.py CHANGED
@@ -18,8 +18,8 @@ def load_models():
18
 
19
  # Load Image Generation Model (Stable Diffusion)
20
  st.write("Loading image generation model...")
21
- # Using a smaller, more memory-efficient model
22
- model_id = "prompthero/openjourney-v4"
23
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32)
24
  if torch.cuda.is_available():
25
  pipe = pipe.to("cuda")
@@ -81,16 +81,38 @@ with st.sidebar:
81
 
82
  # ---- Main Content Area ----
83
  if feature_selection == "Image Generator":
84
- st.header("Image Generation 🖼️")
85
- st.markdown("Enter your prompt and let the AI create an image from scratch.")
86
- prompt = st.text_input("Enter your image prompt:")
87
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  if st.button("Generate Image"):
89
- if prompt:
90
  with st.spinner("Generating image with Stable Diffusion..."):
91
  try:
92
- image = image_gen_pipe(prompt).images[0]
93
- st.image(image, caption=f"Generated from: {prompt}")
94
  except Exception as e:
95
  st.error(f"Error generating image. The model might have run out of memory. Error: {e}")
96
  else:
 
18
 
19
  # Load Image Generation Model (Stable Diffusion)
20
  st.write("Loading image generation model...")
21
+ # Using a new, very lightweight model
22
+ model_id = "segmind/tiny-sd"
23
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32)
24
  if torch.cuda.is_available():
25
  pipe = pipe.to("cuda")
 
81
 
82
  # ---- Main Content Area ----
83
  if feature_selection == "Image Generator":
84
+ st.header("Voice-Controlled Image Generation 🖼️")
85
+ st.markdown("Speak your prompt and let the AI create a masterpiece!")
86
+
87
+ audio_bytes = audio_recorder(
88
+ text="Click to record your prompt...",
89
+ recording_color="#e8b62c",
90
+ neutral_color="#6aa260",
91
+ icon_name="mic",
92
+ icon_size="2x",
93
+ key="image_audio_recorder"
94
+ )
95
+
96
+ prompt = ""
97
+ if audio_bytes:
98
+ st.audio(audio_bytes, format="audio/wav")
99
+
100
+ # --- Placeholder for Transcription Logic ---
101
+ st.info("Transcription feature is disabled in this version. Please type your prompt below.")
102
+ # To make this fully functional, you would need to add a
103
+ # speech-to-text model here (e.g., from transformers).
104
+ # --- End Placeholder ---
105
+
106
+ st.write(f"**Your transcribed prompt:** {prompt}")
107
+
108
+ text_prompt = st.text_input("Or type your prompt here:", value="")
109
+
110
  if st.button("Generate Image"):
111
+ if text_prompt:
112
  with st.spinner("Generating image with Stable Diffusion..."):
113
  try:
114
+ image = image_gen_pipe(text_prompt).images[0]
115
+ st.image(image, caption=f"Generated from: {text_prompt}")
116
  except Exception as e:
117
  st.error(f"Error generating image. The model might have run out of memory. Error: {e}")
118
  else: