Mueris commited on
Commit
f7f1eba
·
verified ·
1 Parent(s): 590c6f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -47,20 +47,18 @@ def toggle_question(model_choice):
47
  return gr.update(interactive=True)
48
 
49
 
50
- # -----------------------
51
- # Load gallery image
52
- # -----------------------
53
- def load_example_image(img_path):
54
- if isinstance(img_path, list):
55
- img_path = img_path[0]
56
- if os.path.exists(img_path):
57
- return Image.open(img_path)
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
- # ---- FIXED GALLERY FORMAT ----
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/bir_grup_asker.jpg",
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
- # ---- FIXED GALLERY SELECT ----
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(share=False)
 
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()