Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- fusion-app/app_api.py +7 -0
- fusion-app/app_local.py +1 -1
fusion-app/app_api.py
CHANGED
|
@@ -14,6 +14,7 @@ HERE = Path(__file__).parent
|
|
| 14 |
LABEL_ITEMS = json.loads((HERE / "labels.json").read_text())["labels"]
|
| 15 |
LABELS = [x["name"] for x in LABEL_ITEMS]
|
| 16 |
PROMPTS = [x["prompt"] for x in LABEL_ITEMS]
|
|
|
|
| 17 |
|
| 18 |
CLIP_MODEL = "openai/clip-vit-base-patch32"
|
| 19 |
W2V2_MODEL = "facebook/wav2vec2-base"
|
|
@@ -142,6 +143,9 @@ def top1_label(p: np.ndarray) -> str:
|
|
| 142 |
return LABELS[int(np.argmax(p))]
|
| 143 |
|
| 144 |
def predict_video(video, alpha=0.7):
|
|
|
|
|
|
|
|
|
|
| 145 |
t0 = time.time()
|
| 146 |
|
| 147 |
# FULL video analysis
|
|
@@ -178,6 +182,9 @@ def predict_video(video, alpha=0.7):
|
|
| 178 |
return pred, probs, lat
|
| 179 |
|
| 180 |
def predict_image_audio(image: Image.Image, audio_path: str, alpha=0.7):
|
|
|
|
|
|
|
|
|
|
| 181 |
t0 = time.time()
|
| 182 |
wave = load_audio_16k(audio_path)
|
| 183 |
|
|
|
|
| 14 |
LABEL_ITEMS = json.loads((HERE / "labels.json").read_text())["labels"]
|
| 15 |
LABELS = [x["name"] for x in LABEL_ITEMS]
|
| 16 |
PROMPTS = [x["prompt"] for x in LABEL_ITEMS]
|
| 17 |
+
CSV_API = HERE / "runs_api.csv"
|
| 18 |
|
| 19 |
CLIP_MODEL = "openai/clip-vit-base-patch32"
|
| 20 |
W2V2_MODEL = "facebook/wav2vec2-base"
|
|
|
|
| 143 |
return LABELS[int(np.argmax(p))]
|
| 144 |
|
| 145 |
def predict_video(video, alpha=0.7):
|
| 146 |
+
if HF_TOKEN is None:
|
| 147 |
+
return "Error: HuggingFace token required", {"error": "Please set HF_Token environment variable to use API features"}, {"error": "No token available"}
|
| 148 |
+
|
| 149 |
t0 = time.time()
|
| 150 |
|
| 151 |
# FULL video analysis
|
|
|
|
| 182 |
return pred, probs, lat
|
| 183 |
|
| 184 |
def predict_image_audio(image: Image.Image, audio_path: str, alpha=0.7):
|
| 185 |
+
if HF_TOKEN is None:
|
| 186 |
+
return "Error: HuggingFace token required", {"error": "Please set HF_Token environment variable to use API features"}, {"error": "No token available"}
|
| 187 |
+
|
| 188 |
t0 = time.time()
|
| 189 |
wave = load_audio_16k(audio_path)
|
| 190 |
|
fusion-app/app_local.py
CHANGED
|
@@ -6,7 +6,7 @@ from fusion import clip_image_probs, wav2vec2_embed_energy, wav2vec2_zero_shot_p
|
|
| 6 |
|
| 7 |
HERE = Path(__file__).parent
|
| 8 |
lables_PATH = HERE / "labels.json"
|
| 9 |
-
|
| 10 |
lables = [x["name"] for x in json.loads(lables_PATH.read_text())["labels"]]
|
| 11 |
|
| 12 |
# lables = [x ["name"] for x in json.load(Path("fusion-app/labels.json").read_text())["labels"]]
|
|
|
|
| 6 |
|
| 7 |
HERE = Path(__file__).parent
|
| 8 |
lables_PATH = HERE / "labels.json"
|
| 9 |
+
CSV_API = HERE / "runs_api.csv"
|
| 10 |
lables = [x["name"] for x in json.loads(lables_PATH.read_text())["labels"]]
|
| 11 |
|
| 12 |
# lables = [x ["name"] for x in json.load(Path("fusion-app/labels.json").read_text())["labels"]]
|