Spaces:
Runtime error
Runtime error
thinh-huynh-re
commited on
Commit
·
e1e899c
1
Parent(s):
ebc167e
Update
Browse files
app.py
CHANGED
@@ -1,8 +1,9 @@
|
|
|
|
1 |
import os
|
|
|
2 |
from typing import List, Tuple
|
3 |
-
import multiprocessing
|
4 |
-
import cv2
|
5 |
|
|
|
6 |
import numpy as np
|
7 |
import pandas as pd
|
8 |
import streamlit as st
|
@@ -104,7 +105,7 @@ def inference(file_path: str):
|
|
104 |
results: List[Tuple[str, float]] = []
|
105 |
for index, value in zip(indices, values):
|
106 |
predicted_label = model.config.id2label[index]
|
107 |
-
print(f"Label: {predicted_label} - {value:.2f}%")
|
108 |
results.append((predicted_label, value))
|
109 |
|
110 |
return pd.DataFrame(results, columns=("Label", "Confidence"))
|
@@ -138,12 +139,16 @@ feature_extractor, model = load_model(model_name)
|
|
138 |
VIDEO_TMP_PATH = os.path.join("tmp", "tmp.mp4")
|
139 |
uploadedfile = st.file_uploader("Upload file", type=["mp4"])
|
140 |
|
|
|
141 |
if uploadedfile is not None:
|
142 |
with st.spinner():
|
143 |
with open(VIDEO_TMP_PATH, "wb") as f:
|
144 |
f.write(uploadedfile.getbuffer())
|
145 |
|
|
|
146 |
with st.spinner("Processing..."):
|
147 |
df = inference(VIDEO_TMP_PATH)
|
|
|
|
|
148 |
st.dataframe(df)
|
149 |
st.video(VIDEO_TMP_PATH)
|
|
|
1 |
+
import multiprocessing
|
2 |
import os
|
3 |
+
import time
|
4 |
from typing import List, Tuple
|
|
|
|
|
5 |
|
6 |
+
import cv2
|
7 |
import numpy as np
|
8 |
import pandas as pd
|
9 |
import streamlit as st
|
|
|
105 |
results: List[Tuple[str, float]] = []
|
106 |
for index, value in zip(indices, values):
|
107 |
predicted_label = model.config.id2label[index]
|
108 |
+
# print(f"Label: {predicted_label} - {value:.2f}%")
|
109 |
results.append((predicted_label, value))
|
110 |
|
111 |
return pd.DataFrame(results, columns=("Label", "Confidence"))
|
|
|
139 |
VIDEO_TMP_PATH = os.path.join("tmp", "tmp.mp4")
|
140 |
uploadedfile = st.file_uploader("Upload file", type=["mp4"])
|
141 |
|
142 |
+
|
143 |
if uploadedfile is not None:
|
144 |
with st.spinner():
|
145 |
with open(VIDEO_TMP_PATH, "wb") as f:
|
146 |
f.write(uploadedfile.getbuffer())
|
147 |
|
148 |
+
start_time = time.time()
|
149 |
with st.spinner("Processing..."):
|
150 |
df = inference(VIDEO_TMP_PATH)
|
151 |
+
end_time = time.time()
|
152 |
+
st.info(f"{end_time - start_time} seconds")
|
153 |
st.dataframe(df)
|
154 |
st.video(VIDEO_TMP_PATH)
|