Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -145,28 +145,110 @@ def generate_description(image, prompt, max_length):
|
|
| 145 |
logger.error(f"Error generating description: {str(e)}", exc_info=True)
|
| 146 |
return f"Error: {str(e)}"
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
with gr.Row():
|
| 152 |
-
with gr.Column():
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
submit_btn.click(
|
| 164 |
-
|
| 165 |
-
inputs=[image_input,
|
| 166 |
-
outputs=
|
| 167 |
)
|
| 168 |
-
|
|
|
|
| 169 |
|
| 170 |
if __name__ == "__main__":
|
| 171 |
-
demo =
|
| 172 |
demo.launch() # Remove ssr=False
|
|
|
|
| 145 |
logger.error(f"Error generating description: {str(e)}", exc_info=True)
|
| 146 |
return f"Error: {str(e)}"
|
| 147 |
|
| 148 |
+
import gradio as gr
|
| 149 |
+
|
| 150 |
+
def create_gradio_interface(generate_description):
|
| 151 |
+
# Enhanced CSS styling
|
| 152 |
+
custom_css = """
|
| 153 |
+
body {
|
| 154 |
+
font-family: 'Segoe UI', sans-serif;
|
| 155 |
+
background-color: #f0fdf4;
|
| 156 |
+
}
|
| 157 |
+
.gradio-container {
|
| 158 |
+
background: linear-gradient(135deg, #e0f7fa, #f8fafc);
|
| 159 |
+
border-radius: 16px;
|
| 160 |
+
padding: 30px;
|
| 161 |
+
box-shadow: 0 10px 24px rgba(0,0,0,0.1);
|
| 162 |
+
max-width: 900px;
|
| 163 |
+
margin: auto;
|
| 164 |
+
}
|
| 165 |
+
h1 {
|
| 166 |
+
color: #0f766e;
|
| 167 |
+
text-align: center;
|
| 168 |
+
font-size: 2.2em;
|
| 169 |
+
margin-bottom: 0.3em;
|
| 170 |
+
}
|
| 171 |
+
.input-container, .output-container {
|
| 172 |
+
background: #ffffff;
|
| 173 |
+
border: 1px solid #cbd5e1;
|
| 174 |
+
border-radius: 10px;
|
| 175 |
+
padding: 20px;
|
| 176 |
+
margin-bottom: 20px;
|
| 177 |
+
}
|
| 178 |
+
.output-container {
|
| 179 |
+
font-size: 1.05em;
|
| 180 |
+
line-height: 1.6;
|
| 181 |
+
background-color: #f0fdf4;
|
| 182 |
+
}
|
| 183 |
+
button {
|
| 184 |
+
background-color: #14b8a6 !important;
|
| 185 |
+
color: white !important;
|
| 186 |
+
border-radius: 8px !important;
|
| 187 |
+
padding: 12px 24px !important;
|
| 188 |
+
font-weight: 600 !important;
|
| 189 |
+
font-size: 1em !important;
|
| 190 |
+
border: none !important;
|
| 191 |
+
margin-top: 10px;
|
| 192 |
+
}
|
| 193 |
+
button:hover {
|
| 194 |
+
background-color: #0d9488 !important;
|
| 195 |
+
}
|
| 196 |
+
.input-label {
|
| 197 |
+
color: #0f766e;
|
| 198 |
+
font-weight: 600;
|
| 199 |
+
margin-bottom: 8px;
|
| 200 |
+
font-size: 0.95em;
|
| 201 |
+
}
|
| 202 |
+
"""
|
| 203 |
+
|
| 204 |
+
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
|
| 205 |
+
gr.Markdown("## 🌼 OmniPhi: Multi-Modal LLM with BLIP or Custom Model")
|
| 206 |
+
|
| 207 |
with gr.Row():
|
| 208 |
+
with gr.Column(scale=1):
|
| 209 |
+
with gr.Group(elem_classes="input-container"):
|
| 210 |
+
image_input = gr.Image(
|
| 211 |
+
type="pil",
|
| 212 |
+
label="Upload Image",
|
| 213 |
+
elem_classes="input-label"
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
with gr.Column(scale=1):
|
| 217 |
+
with gr.Group(elem_classes="input-container"):
|
| 218 |
+
text_input = gr.Textbox(
|
| 219 |
+
label="Text Instruction",
|
| 220 |
+
placeholder="e.g., Describe the image of two dogs in a field of flowers",
|
| 221 |
+
elem_classes="input-label"
|
| 222 |
+
)
|
| 223 |
+
audio_input = gr.Audio(
|
| 224 |
+
sources="microphone",
|
| 225 |
+
type="filepath",
|
| 226 |
+
label="🎤 Record Voice (optional)",
|
| 227 |
+
elem_classes="input-label"
|
| 228 |
+
)
|
| 229 |
+
model_choice = gr.Dropdown(
|
| 230 |
+
choices=["BLIP", "OmniPhi"],
|
| 231 |
+
label="Select Model",
|
| 232 |
+
value="BLIP",
|
| 233 |
+
elem_classes="input-label"
|
| 234 |
+
)
|
| 235 |
+
submit_btn = gr.Button("✨ Generate Description")
|
| 236 |
+
|
| 237 |
+
with gr.Group(elem_classes="output-container"):
|
| 238 |
+
output = gr.Textbox(
|
| 239 |
+
label="Generated Description",
|
| 240 |
+
show_label=True,
|
| 241 |
+
lines=5
|
| 242 |
+
)
|
| 243 |
+
|
| 244 |
submit_btn.click(
|
| 245 |
+
fn=generate_fn,
|
| 246 |
+
inputs=[image_input, text_input, audio_input, model_choice],
|
| 247 |
+
outputs=output
|
| 248 |
)
|
| 249 |
+
|
| 250 |
+
return iface
|
| 251 |
|
| 252 |
if __name__ == "__main__":
|
| 253 |
+
demo = create_gradio_interface()
|
| 254 |
demo.launch() # Remove ssr=False
|