Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,38 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
-
from
|
|
|
|
| 5 |
|
| 6 |
load_dotenv()
|
| 7 |
TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
CSS = """
|
| 10 |
.header {
|
| 11 |
text-align: center;
|
| 12 |
padding: 2rem 1rem;
|
| 13 |
-
background: linear-gradient(135deg, #
|
| 14 |
color: white;
|
| 15 |
border-radius: 8px;
|
| 16 |
margin-bottom: 2rem;
|
|
@@ -18,7 +40,14 @@ CSS = """
|
|
| 18 |
.header h1 { margin: 0; font-size: 2.5em; }
|
| 19 |
.header p { margin: 0.5rem 0; opacity: 0.9; }
|
| 20 |
.header a { color: white; text-decoration: underline; }
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
text-align: center;
|
| 23 |
padding: 1rem;
|
| 24 |
color: #888;
|
|
@@ -82,10 +111,10 @@ with gr.Blocks(
|
|
| 82 |
|
| 83 |
gr.Markdown("### 🎯 Try an Example")
|
| 84 |
gr.Examples(
|
| 85 |
-
examples=
|
| 86 |
-
inputs=[
|
| 87 |
outputs=output,
|
| 88 |
-
fn=lambda
|
| 89 |
cache_examples=False,
|
| 90 |
run_on_click=True,
|
| 91 |
)
|
|
@@ -96,6 +125,6 @@ with gr.Blocks(
|
|
| 96 |
outputs=output,
|
| 97 |
)
|
| 98 |
|
| 99 |
-
gr.HTML('<div class="footer">Developed by Viddexa</div>')
|
| 100 |
|
| 101 |
demo.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from utils import EXAMPLE_ITEMS, analyze, download_image
|
| 6 |
|
| 7 |
load_dotenv()
|
| 8 |
TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
|
| 10 |
+
# Prepare example images
|
| 11 |
+
EXAMPLES_DIR = Path("examples")
|
| 12 |
+
EXAMPLES_DIR.mkdir(exist_ok=True)
|
| 13 |
+
|
| 14 |
+
def prepare_examples():
|
| 15 |
+
"""Download and prepare example images for display."""
|
| 16 |
+
examples = []
|
| 17 |
+
for i, (url, model) in enumerate(EXAMPLE_ITEMS):
|
| 18 |
+
img_path = EXAMPLES_DIR / f"example_{i}.jpg"
|
| 19 |
+
if not img_path.exists():
|
| 20 |
+
try:
|
| 21 |
+
img = download_image(url)
|
| 22 |
+
img.save(img_path, "JPEG", quality=95)
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print(f"Warning: Could not download example {i}: {e}")
|
| 25 |
+
continue
|
| 26 |
+
examples.append([str(img_path), model])
|
| 27 |
+
return examples
|
| 28 |
+
|
| 29 |
+
EXAMPLES = prepare_examples()
|
| 30 |
+
|
| 31 |
CSS = """
|
| 32 |
.header {
|
| 33 |
text-align: center;
|
| 34 |
padding: 2rem 1rem;
|
| 35 |
+
background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);
|
| 36 |
color: white;
|
| 37 |
border-radius: 8px;
|
| 38 |
margin-bottom: 2rem;
|
|
|
|
| 40 |
.header h1 { margin: 0; font-size: 2.5em; }
|
| 41 |
.header p { margin: 0.5rem 0; opacity: 0.9; }
|
| 42 |
.header a { color: white; text-decoration: underline; }
|
| 43 |
+
|
| 44 |
+
/* Hide built-in Gradio footer */
|
| 45 |
+
footer {
|
| 46 |
+
display: none !important;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/* Custom footer styling */
|
| 50 |
+
.custom-footer {
|
| 51 |
text-align: center;
|
| 52 |
padding: 1rem;
|
| 53 |
color: #888;
|
|
|
|
| 111 |
|
| 112 |
gr.Markdown("### 🎯 Try an Example")
|
| 113 |
gr.Examples(
|
| 114 |
+
examples=EXAMPLES,
|
| 115 |
+
inputs=[image_input, model_choice],
|
| 116 |
outputs=output,
|
| 117 |
+
fn=lambda img, model: analyze(img, None, model, TOKEN),
|
| 118 |
cache_examples=False,
|
| 119 |
run_on_click=True,
|
| 120 |
)
|
|
|
|
| 125 |
outputs=output,
|
| 126 |
)
|
| 127 |
|
| 128 |
+
gr.HTML('<div class="custom-footer">Developed by Viddexa</div>')
|
| 129 |
|
| 130 |
demo.launch()
|