nzs234 commited on
Commit
482b4b9
·
verified ·
1 Parent(s): 796e086

Stabilize Space: switch to simple Interface mode, single text output, share=True

Browse files
Files changed (1) hide show
  1. app.py +15 -22
app.py CHANGED
@@ -1,8 +1,8 @@
1
  import json
2
  import threading
3
  from pathlib import Path
4
-
5
- import gradio as gr
6
  import torch
7
  import torch.nn as nn
8
  from PIL import Image
@@ -120,17 +120,11 @@ def _ensure_loaded():
120
 
121
  def predict(img):
122
  if img is None:
123
- yield "error: no image", "status: please upload image first"
124
- return
125
- yield "", "status: starting"
126
  try:
127
- if not _MODEL_READY:
128
- yield "", "status: loading model (first run takes longer)"
129
  _ensure_loaded()
130
  except Exception:
131
- yield f"error: model load failed: {_MODEL_ERR}", "status: failed"
132
- return
133
- yield "", "status: model ready, running inference"
134
  if img.mode != "RGB":
135
  img = img.convert("RGB")
136
  proc = processor(images=img, return_tensors="pt")
@@ -140,17 +134,16 @@ def predict(img):
140
  pred_score = pred_01 * (score_max - score_min) + score_min
141
  score_int = int(round(pred_score))
142
  score_int = max(int(score_min), min(int(score_max), score_int))
143
- yield f"score_{score_int} (raw={pred_score:.4f})", "status: done"
144
-
145
-
146
- with gr.Blocks() as demo:
147
- gr.Markdown("# SigLIP2 Aesthetic Scorer Demo")
148
- inp = gr.Image(type="pil", label="Image")
149
- out = gr.Textbox(label="Result")
150
- status = gr.Textbox(label="Status", value="status: idle")
151
- btn = gr.Button("Predict")
152
- btn.click(fn=predict, inputs=[inp], outputs=[out, status])
153
 
 
 
 
 
 
 
 
 
154
 
155
- demo.queue(default_concurrency_limit=1)
156
- demo.launch(server_name="0.0.0.0", server_port=7860, show_api=False, ssr_mode=False)
 
1
  import json
2
  import threading
3
  from pathlib import Path
4
+
5
+ import gradio as gr
6
  import torch
7
  import torch.nn as nn
8
  from PIL import Image
 
120
 
121
  def predict(img):
122
  if img is None:
123
+ return "error: no image"
 
 
124
  try:
 
 
125
  _ensure_loaded()
126
  except Exception:
127
+ return f"error: model load failed: {_MODEL_ERR}"
 
 
128
  if img.mode != "RGB":
129
  img = img.convert("RGB")
130
  proc = processor(images=img, return_tensors="pt")
 
134
  pred_score = pred_01 * (score_max - score_min) + score_min
135
  score_int = int(round(pred_score))
136
  score_int = max(int(score_min), min(int(score_max), score_int))
137
+ return f"score_{score_int} (raw={pred_score:.4f})"
138
+
 
 
 
 
 
 
 
 
139
 
140
+ demo = gr.Interface(
141
+ fn=predict,
142
+ inputs=gr.Image(type="pil", label="Image"),
143
+ outputs=gr.Textbox(label="Result"),
144
+ title="SigLIP2 Aesthetic Scorer Demo",
145
+ description="Upload image and get score_1..score_9",
146
+ allow_flagging="never",
147
+ )
148
 
149
+ demo.launch(server_name="0.0.0.0", server_port=7860, show_api=False, ssr_mode=False, share=True)