Spaces:
Build error
Build error
CB commited on
Update streamlit_app.py
Browse files- streamlit_app.py +9 -10
streamlit_app.py
CHANGED
|
@@ -30,7 +30,8 @@ DATA_DIR = Path("./data")
|
|
| 30 |
DATA_DIR.mkdir(exist_ok=True)
|
| 31 |
|
| 32 |
st.session_state.setdefault("videos", "")
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
# UI - Sidebar
|
| 36 |
st.sidebar.header("Video Input")
|
|
@@ -40,11 +41,9 @@ settings_exp = st.sidebar.expander("Settings", expanded=False)
|
|
| 40 |
env_api_key = os.getenv("GOOGLE_API_KEY", "")
|
| 41 |
API_KEY = settings_exp.text_input("Google API Key", value=env_api_key, placeholder="Set GOOGLE_API_KEY in .env or enter here")
|
| 42 |
|
| 43 |
-
#
|
| 44 |
raw_model = settings_exp.text_input("Gemini Model (model name)", "gemini-2.0-flash-lite")
|
| 45 |
model_id = raw_model.strip() or "gemini-2.0-flash-lite"
|
| 46 |
-
if not model_id.startswith("models/"):
|
| 47 |
-
model_id = f"models/{model_id}"
|
| 48 |
|
| 49 |
analysis_prompt = settings_exp.text_area("Enter analysis", "watch entire video and describe")
|
| 50 |
settings_exp.text_input("Video Password", key="video-password", placeholder="Enter Video Password (if needed)")
|
|
@@ -109,12 +108,12 @@ if st.sidebar.button("Load Video", use_container_width=True):
|
|
| 109 |
# Sidebar preview & options
|
| 110 |
if st.session_state["videos"]:
|
| 111 |
try:
|
| 112 |
-
st.sidebar.video(st.session_state["videos"], loop=st.session_state.get("loop_video",
|
| 113 |
except Exception:
|
| 114 |
st.sidebar.write("Couldn't preview video")
|
| 115 |
|
| 116 |
with st.sidebar.expander("Options", expanded=False):
|
| 117 |
-
loop_checkbox = st.checkbox("Enable Loop", value=st.session_state.get("loop_video",
|
| 118 |
st.session_state["loop_video"] = loop_checkbox
|
| 119 |
|
| 120 |
if st.button("Clear Video(s)"):
|
|
@@ -183,7 +182,7 @@ def poll_file_processed(file_obj, timeout=180):
|
|
| 183 |
raise TimeoutError("File processing timed out")
|
| 184 |
time.sleep(2)
|
| 185 |
|
| 186 |
-
# Call model (streamlined, using generativeapis host
|
| 187 |
def call_model_with_file(prompt_text: str, uploaded_file_obj):
|
| 188 |
if not API_KEY:
|
| 189 |
raise RuntimeError("No API key provided")
|
|
@@ -199,7 +198,7 @@ def call_model_with_file(prompt_text: str, uploaded_file_obj):
|
|
| 199 |
try:
|
| 200 |
if hasattr(GENAI, "responses") and hasattr(GENAI.responses, "generate"):
|
| 201 |
request = {
|
| 202 |
-
"model": model_id,
|
| 203 |
"input": [{"text": prompt_text, "files": [{"name": file_ref_name}]}],
|
| 204 |
"safetySettings": safety_settings,
|
| 205 |
"maxOutputTokens": 1000,
|
|
@@ -208,8 +207,8 @@ def call_model_with_file(prompt_text: str, uploaded_file_obj):
|
|
| 208 |
except Exception:
|
| 209 |
pass
|
| 210 |
|
| 211 |
-
# Use generativeapis.googleapis.com
|
| 212 |
-
endpoint = f"https://generativeapis.googleapis.com/v1/{model_id}:generate"
|
| 213 |
body = {
|
| 214 |
"input": [
|
| 215 |
{
|
|
|
|
| 30 |
DATA_DIR.mkdir(exist_ok=True)
|
| 31 |
|
| 32 |
st.session_state.setdefault("videos", "")
|
| 33 |
+
# default loop unchecked as requested
|
| 34 |
+
st.session_state.setdefault("loop_video", False)
|
| 35 |
|
| 36 |
# UI - Sidebar
|
| 37 |
st.sidebar.header("Video Input")
|
|
|
|
| 41 |
env_api_key = os.getenv("GOOGLE_API_KEY", "")
|
| 42 |
API_KEY = settings_exp.text_input("Google API Key", value=env_api_key, placeholder="Set GOOGLE_API_KEY in .env or enter here")
|
| 43 |
|
| 44 |
+
# Keep model_id as the short model name (e.g. "gemini-2.0-flash-lite")
|
| 45 |
raw_model = settings_exp.text_input("Gemini Model (model name)", "gemini-2.0-flash-lite")
|
| 46 |
model_id = raw_model.strip() or "gemini-2.0-flash-lite"
|
|
|
|
|
|
|
| 47 |
|
| 48 |
analysis_prompt = settings_exp.text_area("Enter analysis", "watch entire video and describe")
|
| 49 |
settings_exp.text_input("Video Password", key="video-password", placeholder="Enter Video Password (if needed)")
|
|
|
|
| 108 |
# Sidebar preview & options
|
| 109 |
if st.session_state["videos"]:
|
| 110 |
try:
|
| 111 |
+
st.sidebar.video(st.session_state["videos"], loop=st.session_state.get("loop_video", False))
|
| 112 |
except Exception:
|
| 113 |
st.sidebar.write("Couldn't preview video")
|
| 114 |
|
| 115 |
with st.sidebar.expander("Options", expanded=False):
|
| 116 |
+
loop_checkbox = st.checkbox("Enable Loop", value=st.session_state.get("loop_video", False))
|
| 117 |
st.session_state["loop_video"] = loop_checkbox
|
| 118 |
|
| 119 |
if st.button("Clear Video(s)"):
|
|
|
|
| 182 |
raise TimeoutError("File processing timed out")
|
| 183 |
time.sleep(2)
|
| 184 |
|
| 185 |
+
# Call model (streamlined, using generativeapis host path format)
|
| 186 |
def call_model_with_file(prompt_text: str, uploaded_file_obj):
|
| 187 |
if not API_KEY:
|
| 188 |
raise RuntimeError("No API key provided")
|
|
|
|
| 198 |
try:
|
| 199 |
if hasattr(GENAI, "responses") and hasattr(GENAI.responses, "generate"):
|
| 200 |
request = {
|
| 201 |
+
"model": f"models/{model_id}",
|
| 202 |
"input": [{"text": prompt_text, "files": [{"name": file_ref_name}]}],
|
| 203 |
"safetySettings": safety_settings,
|
| 204 |
"maxOutputTokens": 1000,
|
|
|
|
| 207 |
except Exception:
|
| 208 |
pass
|
| 209 |
|
| 210 |
+
# Use generativeapis.googleapis.com with correct path: /v1/models/{model}:generate
|
| 211 |
+
endpoint = f"https://generativeapis.googleapis.com/v1/models/{model_id}:generate"
|
| 212 |
body = {
|
| 213 |
"input": [
|
| 214 |
{
|