Khunanya commited on
Commit
9292604
·
verified ·
1 Parent(s): c18ed12

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -19,7 +19,10 @@ def match_image_text(image, text):
19
 
20
  # คำนวณ cosine similarity
21
  similarity = torch.nn.functional.cosine_similarity(image_embeds, text_embeds).item()
22
- return f"คะแนนความเข้ากัน: {similarity:.4f}"
 
 
 
23
 
24
  # Gradio UI
25
  gr.Interface(
@@ -27,5 +30,5 @@ gr.Interface(
27
  inputs=[gr.Image(type="pil"), gr.Textbox(label="Enter a caption")],
28
  outputs="text",
29
  title="SigLIP2 Image-Text Similarity",
30
- description="ใส่รูป + คำบรรยาย แล้วดูว่าโมเดลคิดว่าแมตช์กันแค่ไหน"
31
  ).launch()
 
19
 
20
  # คำนวณ cosine similarity
21
  similarity = torch.nn.functional.cosine_similarity(image_embeds, text_embeds).item()
22
+
23
+ # ปรับ scale: จาก [-1, 1] → [1, 100]
24
+ score = (similarity + 1) / 2 * 99 + 1 # 1 ถึง 100
25
+ return f"💡 Matching Score: {score:.2f} / 100"
26
 
27
  # Gradio UI
28
  gr.Interface(
 
30
  inputs=[gr.Image(type="pil"), gr.Textbox(label="Enter a caption")],
31
  outputs="text",
32
  title="SigLIP2 Image-Text Similarity",
33
+ description="อัปโหลดภาพและใส่คำบรรยาย แล้วดูว่าเข้ากันแค่ไหน (1-100 คะแนน)"
34
  ).launch()