Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
-
pip install googletrans
|
| 2 |
import spaces
|
| 3 |
import gradio as gr
|
| 4 |
import subprocess
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
|
| 8 |
# Gerekli kütüphanelerin kurulumu
|
| 9 |
subprocess.run(
|
|
@@ -11,7 +9,7 @@ subprocess.run(
|
|
| 11 |
env={"FLASH_ATTENTION_SKIP_CUDA_BUILD": "TRUE"},
|
| 12 |
shell=True,
|
| 13 |
)
|
| 14 |
-
subprocess.run("pip install
|
| 15 |
|
| 16 |
import torch
|
| 17 |
from llava.model.builder import load_pretrained_model
|
|
@@ -24,7 +22,8 @@ from decord import VideoReader, cpu
|
|
| 24 |
import numpy as np
|
| 25 |
|
| 26 |
# Çevirmen nesnesi oluştur
|
| 27 |
-
translator =
|
|
|
|
| 28 |
|
| 29 |
title = "# 🙋🏻♂️🌟Tonic'in 🌋📹LLaVA-Video'suna Hoş Geldiniz!"
|
| 30 |
description1 = """**🌋📹LLaVA-Video-7B-Qwen2**, 🌋📹LLaVA-Video-178K veri seti ve LLaVA-OneVision veri seti üzerinde eğitilmiş 7B parametreli bir modeldir. [**Qwen2 dil modeline dayanmaktadır**](https://huggingface.co/collections/Qwen/qwen2-6659360b33528ced941e557f) ve 32K tokene kadar bağlam penceresini destekler. Model, görüntüleri, çoklu görüntüleri ve videoları işleyebilir ve bunlarla etkileşime girebilir, video analizi için özel optimizasyonlara sahiptir.
|
|
@@ -84,40 +83,43 @@ print("Model başarıyla yüklendi!")
|
|
| 84 |
|
| 85 |
@spaces.GPU
|
| 86 |
def process_video(video_path, question):
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
| 121 |
|
| 122 |
def gradio_interface(video_file, question):
|
| 123 |
if video_file is None:
|
|
|
|
|
|
|
| 1 |
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
import subprocess
|
| 4 |
+
from deep_translator import GoogleTranslator
|
|
|
|
| 5 |
|
| 6 |
# Gerekli kütüphanelerin kurulumu
|
| 7 |
subprocess.run(
|
|
|
|
| 9 |
env={"FLASH_ATTENTION_SKIP_CUDA_BUILD": "TRUE"},
|
| 10 |
shell=True,
|
| 11 |
)
|
| 12 |
+
subprocess.run("pip install deep_translator", shell=True)
|
| 13 |
|
| 14 |
import torch
|
| 15 |
from llava.model.builder import load_pretrained_model
|
|
|
|
| 22 |
import numpy as np
|
| 23 |
|
| 24 |
# Çevirmen nesnesi oluştur
|
| 25 |
+
translator = GoogleTranslator(source='tr', target='en')
|
| 26 |
+
translator_reverse = GoogleTranslator(source='en', target='tr')
|
| 27 |
|
| 28 |
title = "# 🙋🏻♂️🌟Tonic'in 🌋📹LLaVA-Video'suna Hoş Geldiniz!"
|
| 29 |
description1 = """**🌋📹LLaVA-Video-7B-Qwen2**, 🌋📹LLaVA-Video-178K veri seti ve LLaVA-OneVision veri seti üzerinde eğitilmiş 7B parametreli bir modeldir. [**Qwen2 dil modeline dayanmaktadır**](https://huggingface.co/collections/Qwen/qwen2-6659360b33528ced941e557f) ve 32K tokene kadar bağlam penceresini destekler. Model, görüntüleri, çoklu görüntüleri ve videoları işleyebilir ve bunlarla etkileşime girebilir, video analizi için özel optimizasyonlara sahiptir.
|
|
|
|
| 83 |
|
| 84 |
@spaces.GPU
|
| 85 |
def process_video(video_path, question):
|
| 86 |
+
try:
|
| 87 |
+
max_frames_num = 64
|
| 88 |
+
video, frame_time, video_time = load_video(video_path, max_frames_num, 1, force_sample=True)
|
| 89 |
+
video = image_processor.preprocess(video, return_tensors="pt")["pixel_values"].to(device).bfloat16()
|
| 90 |
+
video = [video]
|
| 91 |
|
| 92 |
+
conv_template = "qwen_1_5"
|
| 93 |
+
time_instruction = f"Video {video_time:.2f} saniye sürmektedir ve {len(video[0])} kare uniform olarak örneklenmiştir. Bu kareler {frame_time} konumlarında bulunmaktadır. Lütfen bu videoyla ilgili aşağıdaki soruları cevaplayın."
|
| 94 |
+
|
| 95 |
+
# Soruyu İngilizce'ye çevir
|
| 96 |
+
question_en = translator.translate(question)
|
| 97 |
+
full_question = DEFAULT_IMAGE_TOKEN + f"{time_instruction}\n{question_en}"
|
| 98 |
+
|
| 99 |
+
conv = copy.deepcopy(conv_templates[conv_template])
|
| 100 |
+
conv.append_message(conv.roles[0], full_question)
|
| 101 |
+
conv.append_message(conv.roles[1], None)
|
| 102 |
+
prompt_question = conv.get_prompt()
|
| 103 |
+
|
| 104 |
+
input_ids = tokenizer_image_token(prompt_question, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)
|
| 105 |
+
|
| 106 |
+
with torch.no_grad():
|
| 107 |
+
output = model.generate(
|
| 108 |
+
input_ids,
|
| 109 |
+
images=video,
|
| 110 |
+
modalities=["video"],
|
| 111 |
+
do_sample=False,
|
| 112 |
+
temperature=0,
|
| 113 |
+
max_new_tokens=4096,
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
response = tokenizer.batch_decode(output, skip_special_tokens=True)[0].strip()
|
| 117 |
+
|
| 118 |
+
# Cevabı Türkçe'ye çevir
|
| 119 |
+
response_tr = translator_reverse.translate(response)
|
| 120 |
+
return response_tr
|
| 121 |
+
except Exception as e:
|
| 122 |
+
return f"Bir hata oluştu: {str(e)}"
|
| 123 |
|
| 124 |
def gradio_interface(video_file, question):
|
| 125 |
if video_file is None:
|