darisdzakwanhoesien commited on
Commit
b477b53
·
verified ·
1 Parent(s): 3d7a0d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -26,11 +26,12 @@ def run_videomae(video):
26
  pred_id = outputs.logits.argmax(-1).item()
27
  return {
28
  "model": "VideoMAE",
 
29
  "class": vm_model.config.id2label[pred_id],
30
  "confidence": float(torch.softmax(outputs.logits, -1)[0, pred_id].item()),
31
  }
32
  except Exception as e:
33
- return {"model": "VideoMAE", "error": str(e)}
34
 
35
  # ======================
36
  # 2. LLaVA-Video-Llama-3.1-8B
@@ -38,7 +39,9 @@ def run_videomae(video):
38
  try:
39
  llava_model_id = "weizhiwang/LLaVA-Video-Llama-3.1-8B"
40
  llava_tokenizer = AutoTokenizer.from_pretrained(llava_model_id, trust_remote_code=True)
41
- llava_model = AutoModelForCausalLM.from_pretrained(llava_model_id, trust_remote_code=True).half().cuda().eval()
 
 
42
 
43
  def run_llava(video, prompt):
44
  try:
@@ -46,16 +49,21 @@ try:
46
  output = llava_model.generate(**inputs, max_new_tokens=256)
47
  return {
48
  "model": "LLaVA-Video-Llama-3.1-8B",
 
49
  "output": llava_tokenizer.decode(output[0], skip_special_tokens=True),
50
  }
51
  except Exception as e:
52
- return {"model": "LLaVA-Video-Llama-3.1-8B", "error": str(e)}
53
 
54
  except Exception as outer_error:
55
  llava_load_error = str(outer_error)
56
 
57
  def run_llava(video, prompt):
58
- return {"model": "LLaVA-Video-Llama-3.1-8B", "error": f"LLaVA not available: {llava_load_error}"}
 
 
 
 
59
 
60
  # ======================
61
  # Unified App
 
26
  pred_id = outputs.logits.argmax(-1).item()
27
  return {
28
  "model": "VideoMAE",
29
+ "status": "ok",
30
  "class": vm_model.config.id2label[pred_id],
31
  "confidence": float(torch.softmax(outputs.logits, -1)[0, pred_id].item()),
32
  }
33
  except Exception as e:
34
+ return {"model": "VideoMAE", "status": "failed", "error": str(e)}
35
 
36
  # ======================
37
  # 2. LLaVA-Video-Llama-3.1-8B
 
39
  try:
40
  llava_model_id = "weizhiwang/LLaVA-Video-Llama-3.1-8B"
41
  llava_tokenizer = AutoTokenizer.from_pretrained(llava_model_id, trust_remote_code=True)
42
+ llava_model = AutoModelForCausalLM.from_pretrained(
43
+ llava_model_id, trust_remote_code=True
44
+ ).half().cuda().eval()
45
 
46
  def run_llava(video, prompt):
47
  try:
 
49
  output = llava_model.generate(**inputs, max_new_tokens=256)
50
  return {
51
  "model": "LLaVA-Video-Llama-3.1-8B",
52
+ "status": "ok",
53
  "output": llava_tokenizer.decode(output[0], skip_special_tokens=True),
54
  }
55
  except Exception as e:
56
+ return {"model": "LLaVA-Video-Llama-3.1-8B", "status": "failed", "error": str(e)}
57
 
58
  except Exception as outer_error:
59
  llava_load_error = str(outer_error)
60
 
61
  def run_llava(video, prompt):
62
+ return {
63
+ "model": "LLaVA-Video-Llama-3.1-8B",
64
+ "status": "failed",
65
+ "error": f"LLaVA not available: {llava_load_error}",
66
+ }
67
 
68
  # ======================
69
  # Unified App