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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -8
app.py CHANGED
@@ -18,8 +18,7 @@ def load_models():
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")
@@ -39,7 +38,7 @@ st.set_page_config(
39
  initial_sidebar_state="expanded"
40
  )
41
 
42
- # Custom CSS for a classic and elegant look
43
  st.markdown(
44
  """
45
  <style>
@@ -49,6 +48,8 @@ st.markdown(
49
  .sidebar .sidebar-content { background-color: #ffffff; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); }
50
  h1 { color: #333333; font-family: serif; text-align: center; }
51
  h2 { color: #555555; font-family: serif; }
 
 
52
  .stButton>button {
53
  background-color: #4CAF50; color: white; border: none; padding: 10px 24px;
54
  text-align: center; text-decoration: none; display: inline-block;
@@ -56,6 +57,32 @@ st.markdown(
56
  transition: all 0.3s ease-in-out;
57
  }
58
  .stButton>button:hover { background-color: #45a049; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  .stImage { border-radius: 12px; }
60
  </style>
61
  """,
@@ -84,14 +111,18 @@ 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:
@@ -103,9 +134,9 @@ if feature_selection == "Image Generator":
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:
 
18
 
19
  # Load Image Generation Model (Stable Diffusion)
20
  st.write("Loading image generation model...")
21
+ model_id = "segmind/tiny-sd" # Using a very lightweight model
 
22
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32)
23
  if torch.cuda.is_available():
24
  pipe = pipe.to("cuda")
 
38
  initial_sidebar_state="expanded"
39
  )
40
 
41
+ # Custom CSS for a classic and elegant look, including the new recording button style
42
  st.markdown(
43
  """
44
  <style>
 
48
  .sidebar .sidebar-content { background-color: #ffffff; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); }
49
  h1 { color: #333333; font-family: serif; text-align: center; }
50
  h2 { color: #555555; font-family: serif; }
51
+
52
+ /* General Streamlit button style */
53
  .stButton>button {
54
  background-color: #4CAF50; color: white; border: none; padding: 10px 24px;
55
  text-align: center; text-decoration: none; display: inline-block;
 
57
  transition: all 0.3s ease-in-out;
58
  }
59
  .stButton>button:hover { background-color: #45a049; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); }
60
+
61
+ /* Styling for the audio recorder button */
62
+ .audio-recorder {
63
+ background-color: #FF6347; /* Tomato red, visually distinct */
64
+ color: white;
65
+ border: none;
66
+ padding: 12px 28px;
67
+ text-align: center;
68
+ text-decoration: none;
69
+ display: inline-block;
70
+ font-size: 18px;
71
+ margin: 10px 0;
72
+ cursor: pointer;
73
+ border-radius: 15px;
74
+ box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
75
+ transition: all 0.3s ease-in-out;
76
+ font-weight: bold;
77
+ display: flex;
78
+ align-items: center;
79
+ justify-content: center;
80
+ }
81
+ .audio-recorder:hover {
82
+ background-color: #E64A19; /* Darker red on hover */
83
+ box-shadow: 0 6px 12px 0 rgba(0,0,0,0.3);
84
+ transform: translateY(-2px);
85
+ }
86
  .stImage { border-radius: 12px; }
87
  </style>
88
  """,
 
111
  st.header("Voice-Controlled Image Generation 🖼️")
112
  st.markdown("Speak your prompt and let the AI create a masterpiece!")
113
 
114
+ # Applying the custom class to the audio recorder
115
+ st.markdown('<div class="audio-recorder-container">', unsafe_allow_html=True)
116
  audio_bytes = audio_recorder(
117
+ text="🎙️ Click to Record Prompt", # More explicit text
118
+ recording_color="#E64A19", # Darker red for recording state
119
+ neutral_color="#FF6347", # Tomato red for neutral state
120
  icon_name="mic",
121
  icon_size="2x",
122
  key="image_audio_recorder"
123
  )
124
+ st.markdown('</div>', unsafe_allow_html=True)
125
+
126
 
127
  prompt = ""
128
  if audio_bytes:
 
134
  # speech-to-text model here (e.g., from transformers).
135
  # --- End Placeholder ---
136
 
137
+ st.write(f"**Your recorded (placeholder) prompt:** {prompt}") # Clarify it's a placeholder
138
 
139
+ text_prompt = st.text_input("Or type your prompt here (overrides voice):", value="")
140
 
141
  if st.button("Generate Image"):
142
  if text_prompt: