Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -24,10 +24,19 @@ def answer_question(image, question):
|
|
24 |
return "Lütfen bir soru girin."
|
25 |
inputs = processor(images=image, text=question, return_tensors="pt").to(device)
|
26 |
with torch.no_grad():
|
27 |
-
output = model.generate(
|
|
|
|
|
|
|
|
|
|
|
28 |
answer = processor.decode(output[0], skip_special_tokens=True)[len(question):].strip()
|
29 |
return f"PaliGemma’ya göre: {answer}"
|
30 |
|
|
|
|
|
|
|
|
|
31 |
# Gradio arayüzü
|
32 |
interface = gr.Interface(
|
33 |
fn=answer_question,
|
@@ -36,8 +45,12 @@ interface = gr.Interface(
|
|
36 |
gr.Textbox(label="Sorunuzu Sorun", placeholder="Bu görüntüde ne var?")
|
37 |
],
|
38 |
outputs=gr.Textbox(label="Cevap"),
|
39 |
-
title="PaliGemma
|
40 |
-
description="Bir görüntü yükleyin ve hakkında istediğiniz soruyu sorun. PaliGemma cevaplayacak!"
|
|
|
|
|
|
|
|
|
41 |
)
|
42 |
|
43 |
interface.launch()
|
|
|
24 |
return "Lütfen bir soru girin."
|
25 |
inputs = processor(images=image, text=question, return_tensors="pt").to(device)
|
26 |
with torch.no_grad():
|
27 |
+
output = model.generate(
|
28 |
+
**inputs,
|
29 |
+
max_new_tokens=100, # Daha uzun cevaplar için artırıldı
|
30 |
+
temperature=0.7, # Yaratıcılığı biraz artırmak için
|
31 |
+
do_sample=True # Örnekleme ile daha çeşitli cevaplar
|
32 |
+
)
|
33 |
answer = processor.decode(output[0], skip_special_tokens=True)[len(question):].strip()
|
34 |
return f"PaliGemma’ya göre: {answer}"
|
35 |
|
36 |
+
# Örnek görseller (Space’in kök dizininde olmalı)
|
37 |
+
example_image_1 = "example_1.jpg" # İlk örnek görsel
|
38 |
+
example_image_2 = "example_2.jpg" # İkinci örnek görsel
|
39 |
+
|
40 |
# Gradio arayüzü
|
41 |
interface = gr.Interface(
|
42 |
fn=answer_question,
|
|
|
45 |
gr.Textbox(label="Sorunuzu Sorun", placeholder="Bu görüntüde ne var?")
|
46 |
],
|
47 |
outputs=gr.Textbox(label="Cevap"),
|
48 |
+
title="PaliGemma ile Görsel Soru Yanıtlama",
|
49 |
+
description="Bir görüntü yükleyin ve hakkında istediğiniz soruyu sorun. PaliGemma cevaplayacak!",
|
50 |
+
examples=[
|
51 |
+
[example_image_1, "Bu görselde kaç kedi var?"],
|
52 |
+
[example_image_2, "Bu görseli bana açıklayabilir misin?"]
|
53 |
+
]
|
54 |
)
|
55 |
|
56 |
interface.launch()
|