Commit ·
d3b4e50
1
Parent(s): 13ce174
fina p3
Browse files- src/inference_logic.py +10 -6
src/inference_logic.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import torch
|
| 2 |
import re
|
| 3 |
import ast
|
| 4 |
import sys
|
|
@@ -9,6 +8,11 @@ import json
|
|
| 9 |
import datetime
|
| 10 |
import requests
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
try:
|
| 13 |
from transformers import Qwen3VLForConditionalGeneration, AutoProcessor
|
| 14 |
from peft import PeftModel
|
|
@@ -72,8 +76,8 @@ def load_models():
|
|
| 72 |
|
| 73 |
if base_model is not None: return
|
| 74 |
|
| 75 |
-
if not torch.cuda.is_available():
|
| 76 |
-
logger.warning("CUDA is not available. This application requires a GPU for local models. Switching to LITE_MODE.")
|
| 77 |
LITE_MODE = True
|
| 78 |
return
|
| 79 |
|
|
@@ -107,7 +111,7 @@ def switch_active_model(model_name: str):
|
|
| 107 |
|
| 108 |
def inference_step(video_path, prompt, generation_kwargs, sampling_fps, pred_glue=None):
|
| 109 |
global processor, active_model
|
| 110 |
-
if active_model is None: raise RuntimeError("Models not loaded.")
|
| 111 |
|
| 112 |
messages =[
|
| 113 |
{"role": "user", "content":[
|
|
@@ -321,7 +325,7 @@ async def run_gemini_labeling_pipeline(video_path: str, caption: str, transcript
|
|
| 321 |
|
| 322 |
macro_prompt = FCOT_MACRO_PROMPT.format(system_persona=system_persona, caption=caption, transcript=transcript)
|
| 323 |
save_debug_log(request_id, 'prompt', macro_prompt, attempt, 'fcot_macro')
|
| 324 |
-
inputs1 =
|
| 325 |
if uploaded_file: inputs1.insert(0, uploaded_file)
|
| 326 |
res1 = await loop.run_in_executor(None, lambda: chat.send_message(inputs1))
|
| 327 |
macro_hypothesis = res1.text
|
|
@@ -713,4 +717,4 @@ async def run_nrp_labeling_pipeline(video_path: str, caption: str, transcript: s
|
|
| 713 |
|
| 714 |
except Exception as e:
|
| 715 |
yield f"ERROR: {e}"
|
| 716 |
-
logger.error("NRP Labeling Error", exc_info=True)
|
|
|
|
|
|
|
| 1 |
import re
|
| 2 |
import ast
|
| 3 |
import sys
|
|
|
|
| 8 |
import datetime
|
| 9 |
import requests
|
| 10 |
|
| 11 |
+
try:
|
| 12 |
+
import torch
|
| 13 |
+
except ImportError:
|
| 14 |
+
torch = None
|
| 15 |
+
|
| 16 |
try:
|
| 17 |
from transformers import Qwen3VLForConditionalGeneration, AutoProcessor
|
| 18 |
from peft import PeftModel
|
|
|
|
| 76 |
|
| 77 |
if base_model is not None: return
|
| 78 |
|
| 79 |
+
if torch is None or not torch.cuda.is_available():
|
| 80 |
+
logger.warning("CUDA is not available or torch is missing. This application requires a GPU for local models. Switching to LITE_MODE.")
|
| 81 |
LITE_MODE = True
|
| 82 |
return
|
| 83 |
|
|
|
|
| 111 |
|
| 112 |
def inference_step(video_path, prompt, generation_kwargs, sampling_fps, pred_glue=None):
|
| 113 |
global processor, active_model
|
| 114 |
+
if active_model is None or torch is None: raise RuntimeError("Models not loaded.")
|
| 115 |
|
| 116 |
messages =[
|
| 117 |
{"role": "user", "content":[
|
|
|
|
| 325 |
|
| 326 |
macro_prompt = FCOT_MACRO_PROMPT.format(system_persona=system_persona, caption=caption, transcript=transcript)
|
| 327 |
save_debug_log(request_id, 'prompt', macro_prompt, attempt, 'fcot_macro')
|
| 328 |
+
inputs1 =[macro_prompt]
|
| 329 |
if uploaded_file: inputs1.insert(0, uploaded_file)
|
| 330 |
res1 = await loop.run_in_executor(None, lambda: chat.send_message(inputs1))
|
| 331 |
macro_hypothesis = res1.text
|
|
|
|
| 717 |
|
| 718 |
except Exception as e:
|
| 719 |
yield f"ERROR: {e}"
|
| 720 |
+
logger.error("NRP Labeling Error", exc_info=True)
|