Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -16,20 +16,19 @@ model_od.to("cuda:0")
|
|
16 |
|
17 |
@spaces.GPU
|
18 |
def bot_streaming(message, history, max_tokens, temperature, top_p, top_k, repetition_penalty):
|
|
|
19 |
if message.files:
|
20 |
image = message.files[-1].path
|
21 |
else:
|
22 |
# if there's no image uploaded for this turn, look for images in the past turns
|
23 |
# kept inside tuples, take the last one
|
24 |
for hist in history:
|
25 |
-
print(hist)
|
26 |
if type(hist[0])==tuple:
|
27 |
-
[('/tmp/gradio/d2358aee8efc2902714f1b4ccc3089ec858104a3e7c8fc7a6ae702e1d0bcbcb0/oguzhan.jpg',), None]
|
28 |
image = hist[0][0]
|
29 |
|
30 |
if image is None:
|
31 |
gr.Error("Lütfen önce bir resim yükleyin.")
|
32 |
-
|
33 |
prompt = f"{message.text}"
|
34 |
image = Image.open(image).convert("RGB")
|
35 |
inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda:0")
|
@@ -61,7 +60,7 @@ logo_path = "static/images/logo-color-v2.png"
|
|
61 |
|
62 |
PLACEHOLDER = f"""
|
63 |
<div style="display: flex; flex-direction: column; align-items: center; text-align: center; margin: 30px">
|
64 |
-
<img src="/file={logo_path}" style="width: 60%; height: auto;">
|
65 |
<h3>Resim yükleyin ve bir soru sorun</h3>
|
66 |
</div>
|
67 |
"""
|
@@ -76,32 +75,23 @@ with gr.Accordion("Generation parameters", open=False) as parameter_accordion:
|
|
76 |
repeat_penalty_item = gr.Slider(0, 2, value=1.2, label="Repeat penalty")
|
77 |
|
78 |
demo = gr.ChatInterface(
|
79 |
-
title="TraVisionLM -
|
80 |
description="",
|
81 |
fn=bot_streaming,
|
82 |
chatbot=gr.Chatbot(placeholder=PLACEHOLDER, scale=1),
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
additional_inputs=[max_tokens_item, temperature_item, top_p_item, top_k_item, repeat_penalty_item],
|
85 |
additional_inputs_accordion=parameter_accordion,
|
86 |
stop_btn="Stop Generation",
|
87 |
multimodal=True
|
88 |
)
|
89 |
|
90 |
-
|
91 |
-
# gr.Image("tiger.jpg")
|
92 |
-
# gr.Button("New Tiger")
|
93 |
-
|
94 |
-
# demo = gr.ChatInterface(fn=bot_streaming, title="TraVisionLM - Turkish Visual Language Model",
|
95 |
-
# # examples=[{"text": "", "files":[""]},{"text": "", "files":[""]}],
|
96 |
-
# description="",
|
97 |
-
# additional_inputs=[
|
98 |
-
# gr.Slider(64, 1024, value=512, step=64, label="Max tokens"),
|
99 |
-
# gr.Slider(0.1, 2, value=0.6, step=0.1, label="Temperature"),
|
100 |
-
# gr.Slider(0, 1.0, value=0.9, step=0.05, label="Top_p"),
|
101 |
-
# gr.Slider(0, 100, value=50, label="Top_k"),
|
102 |
-
# gr.Slider(0, 2, value=1.2, label="Repeat penalty"),
|
103 |
-
# ],
|
104 |
-
# additional_inputs_accordion_name="Text generation parameters",
|
105 |
-
# # additional_inputs_accordion=
|
106 |
-
# stop_btn="Stop Generation", multimodal=True)
|
107 |
demo.launch(max_file_size="5mb")
|
|
|
16 |
|
17 |
@spaces.GPU
|
18 |
def bot_streaming(message, history, max_tokens, temperature, top_p, top_k, repetition_penalty):
|
19 |
+
print(max_tokens, temperature, top_p, top_k, repetition_penalty)
|
20 |
if message.files:
|
21 |
image = message.files[-1].path
|
22 |
else:
|
23 |
# if there's no image uploaded for this turn, look for images in the past turns
|
24 |
# kept inside tuples, take the last one
|
25 |
for hist in history:
|
|
|
26 |
if type(hist[0])==tuple:
|
|
|
27 |
image = hist[0][0]
|
28 |
|
29 |
if image is None:
|
30 |
gr.Error("Lütfen önce bir resim yükleyin.")
|
31 |
+
|
32 |
prompt = f"{message.text}"
|
33 |
image = Image.open(image).convert("RGB")
|
34 |
inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda:0")
|
|
|
60 |
|
61 |
PLACEHOLDER = f"""
|
62 |
<div style="display: flex; flex-direction: column; align-items: center; text-align: center; margin: 30px">
|
63 |
+
<img src="/file={logo_path}" style="width: 60%; height: auto; opacity: 80%">
|
64 |
<h3>Resim yükleyin ve bir soru sorun</h3>
|
65 |
</div>
|
66 |
"""
|
|
|
75 |
repeat_penalty_item = gr.Slider(0, 2, value=1.2, label="Repeat penalty")
|
76 |
|
77 |
demo = gr.ChatInterface(
|
78 |
+
title="TraVisionLM - Çok Hızlı Türkçe Görsel Dil Modeli",
|
79 |
description="",
|
80 |
fn=bot_streaming,
|
81 |
chatbot=gr.Chatbot(placeholder=PLACEHOLDER, scale=1),
|
82 |
+
examples=[
|
83 |
+
{"text": "Detaylı açıkla", "files":["family.jpg"]},
|
84 |
+
{"text": "Görüntüde uçaklar ne yapıyor?", "files":["plane.jpg"]},
|
85 |
+
{"text": "Kısaca açıkla", "files":["dog.jpg"]},
|
86 |
+
{"text": "Tren istasyonu kalabalık mı yoksa boş mu?", "files":["train.jpg"]},
|
87 |
+
{"text": "Resimdeki araba hangi renk?", "files":["car.jpg"]},
|
88 |
+
{"text": "Görüntünün odak noktası nedir?", "files":["mandog.jpg"]}
|
89 |
+
],
|
90 |
additional_inputs=[max_tokens_item, temperature_item, top_p_item, top_k_item, repeat_penalty_item],
|
91 |
additional_inputs_accordion=parameter_accordion,
|
92 |
stop_btn="Stop Generation",
|
93 |
multimodal=True
|
94 |
)
|
95 |
|
96 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
demo.launch(max_file_size="5mb")
|