Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,20 +47,18 @@ def toggle_question(model_choice):
|
|
| 47 |
return gr.update(interactive=True)
|
| 48 |
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
#
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
if os.path.exists(
|
| 57 |
-
return Image.open(
|
| 58 |
return None
|
| 59 |
|
| 60 |
|
| 61 |
-
|
| 62 |
-
# CSS
|
| 63 |
-
# -----------------------
|
| 64 |
css = """
|
| 65 |
#col-container { max-width: 1100px; margin: auto; }
|
| 66 |
.output-box {
|
|
@@ -71,6 +69,7 @@ css = """
|
|
| 71 |
"""
|
| 72 |
|
| 73 |
|
|
|
|
| 74 |
with gr.Blocks(css=css) as demo:
|
| 75 |
|
| 76 |
gr.HTML("<h1 style='text-align:center;'>🇹🇷 TAMGA — Çok Modelli Görsel Dil Sistemi</h1>")
|
|
@@ -78,7 +77,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 78 |
|
| 79 |
with gr.Row(elem_id="col-container"):
|
| 80 |
|
| 81 |
-
# LEFT PANEL
|
| 82 |
with gr.Column(scale=1):
|
| 83 |
|
| 84 |
model_choice = gr.Dropdown(
|
|
@@ -89,7 +87,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 89 |
|
| 90 |
image = gr.Image(type="numpy", label="📷 Görsel Yükle")
|
| 91 |
|
| 92 |
-
#
|
| 93 |
example_gallery = gr.Gallery(
|
| 94 |
label="Örnek Görseller",
|
| 95 |
columns=4,
|
|
@@ -97,11 +95,12 @@ with gr.Blocks(css=css) as demo:
|
|
| 97 |
preview=True
|
| 98 |
)
|
| 99 |
|
|
|
|
| 100 |
example_gallery.value = [
|
| 101 |
-
"examples/
|
| 102 |
"examples/tank.jpg",
|
| 103 |
"examples/ucak.jpg",
|
| 104 |
-
"examples/ucaklar.jpeg"
|
| 105 |
]
|
| 106 |
|
| 107 |
question = gr.Textbox(
|
|
@@ -111,20 +110,21 @@ with gr.Blocks(css=css) as demo:
|
|
| 111 |
|
| 112 |
run_btn = gr.Button("Çalıştır", variant="primary")
|
| 113 |
|
| 114 |
-
# RIGHT PANEL
|
| 115 |
with gr.Column(scale=1):
|
| 116 |
output = gr.Markdown(elem_classes="output-box")
|
| 117 |
|
| 118 |
|
|
|
|
| 119 |
model_choice.change(toggle_question, inputs=model_choice, outputs=question)
|
| 120 |
|
| 121 |
-
#
|
| 122 |
example_gallery.select(
|
| 123 |
fn=load_example_image,
|
| 124 |
inputs=example_gallery,
|
| 125 |
outputs=image
|
| 126 |
)
|
| 127 |
|
|
|
|
| 128 |
run_btn.click(
|
| 129 |
fn=answer,
|
| 130 |
inputs=[model_choice, image, question],
|
|
@@ -132,5 +132,5 @@ with gr.Blocks(css=css) as demo:
|
|
| 132 |
)
|
| 133 |
|
| 134 |
|
| 135 |
-
|
| 136 |
-
demo.launch(
|
|
|
|
| 47 |
return gr.update(interactive=True)
|
| 48 |
|
| 49 |
|
| 50 |
+
|
| 51 |
+
def load_example_image(path):
|
| 52 |
+
# Gallery returns a list (value, index), so handle list type
|
| 53 |
+
if isinstance(path, list):
|
| 54 |
+
path = path[0]
|
| 55 |
+
|
| 56 |
+
if os.path.exists(path):
|
| 57 |
+
return Image.open(path)
|
| 58 |
return None
|
| 59 |
|
| 60 |
|
| 61 |
+
|
|
|
|
|
|
|
| 62 |
css = """
|
| 63 |
#col-container { max-width: 1100px; margin: auto; }
|
| 64 |
.output-box {
|
|
|
|
| 69 |
"""
|
| 70 |
|
| 71 |
|
| 72 |
+
|
| 73 |
with gr.Blocks(css=css) as demo:
|
| 74 |
|
| 75 |
gr.HTML("<h1 style='text-align:center;'>🇹🇷 TAMGA — Çok Modelli Görsel Dil Sistemi</h1>")
|
|
|
|
| 77 |
|
| 78 |
with gr.Row(elem_id="col-container"):
|
| 79 |
|
|
|
|
| 80 |
with gr.Column(scale=1):
|
| 81 |
|
| 82 |
model_choice = gr.Dropdown(
|
|
|
|
| 87 |
|
| 88 |
image = gr.Image(type="numpy", label="📷 Görsel Yükle")
|
| 89 |
|
| 90 |
+
# GALLERY — strictly string paths only
|
| 91 |
example_gallery = gr.Gallery(
|
| 92 |
label="Örnek Görseller",
|
| 93 |
columns=4,
|
|
|
|
| 95 |
preview=True
|
| 96 |
)
|
| 97 |
|
| 98 |
+
# <<< YOUR REAL FILES >>>
|
| 99 |
example_gallery.value = [
|
| 100 |
+
"examples/Bir_grup_asker.jpg",
|
| 101 |
"examples/tank.jpg",
|
| 102 |
"examples/ucak.jpg",
|
| 103 |
+
"examples/ucaklar.jpeg",
|
| 104 |
]
|
| 105 |
|
| 106 |
question = gr.Textbox(
|
|
|
|
| 110 |
|
| 111 |
run_btn = gr.Button("Çalıştır", variant="primary")
|
| 112 |
|
|
|
|
| 113 |
with gr.Column(scale=1):
|
| 114 |
output = gr.Markdown(elem_classes="output-box")
|
| 115 |
|
| 116 |
|
| 117 |
+
# Disable/enable question box based on model
|
| 118 |
model_choice.change(toggle_question, inputs=model_choice, outputs=question)
|
| 119 |
|
| 120 |
+
# Gallery selection loads the image
|
| 121 |
example_gallery.select(
|
| 122 |
fn=load_example_image,
|
| 123 |
inputs=example_gallery,
|
| 124 |
outputs=image
|
| 125 |
)
|
| 126 |
|
| 127 |
+
# Run model
|
| 128 |
run_btn.click(
|
| 129 |
fn=answer,
|
| 130 |
inputs=[model_choice, image, question],
|
|
|
|
| 132 |
)
|
| 133 |
|
| 134 |
|
| 135 |
+
# Required for HuggingFace Spaces
|
| 136 |
+
demo.launch()
|