Spaces:
Build error
Build error
CB commited on
Update streamlit_app.py
Browse files- streamlit_app.py +20 -5
streamlit_app.py
CHANGED
|
@@ -105,6 +105,15 @@ def download_video_ytdlp(url: str, save_dir: str, video_password: str = None) ->
|
|
| 105 |
raise FileNotFoundError("Downloaded video not found")
|
| 106 |
return convert_video_to_mp4(matches[0])
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
# configure GENAI if available
|
| 109 |
if API_KEY and HAS_GENAI:
|
| 110 |
try:
|
|
@@ -168,7 +177,7 @@ def upload_video_sdk(filepath: str):
|
|
| 168 |
|
| 169 |
def wait_for_processed(file_obj, timeout=180):
|
| 170 |
start = time.time()
|
| 171 |
-
name =
|
| 172 |
if not name:
|
| 173 |
return file_obj
|
| 174 |
while True:
|
|
@@ -201,18 +210,24 @@ if st.button("Generate the story", type="primary"):
|
|
| 201 |
else:
|
| 202 |
# fallback: call GENAI.responses.generate directly
|
| 203 |
with st.spinner("Generating description via SDK..."):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
request = {
|
| 205 |
"model": f"models/{model_id}",
|
| 206 |
-
"input": [{"text": prompt_text, "files": [{"name":
|
| 207 |
"safetySettings": safety_settings,
|
| 208 |
"maxOutputTokens": 1000,
|
| 209 |
}
|
| 210 |
res = GENAI.responses.generate(**request)
|
| 211 |
out = ""
|
| 212 |
# basic extraction
|
| 213 |
-
for item in res
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
| 216 |
out += getattr(c, "text", "") or c.get("text", "")
|
| 217 |
if not out:
|
| 218 |
out = getattr(res, "text", None) or json.dumps(res, default=str)
|
|
|
|
| 105 |
raise FileNotFoundError("Downloaded video not found")
|
| 106 |
return convert_video_to_mp4(matches[0])
|
| 107 |
|
| 108 |
+
# Helper: robustly extract name/id from SDK file object or dict
|
| 109 |
+
def file_name_or_id(file_obj):
|
| 110 |
+
if file_obj is None:
|
| 111 |
+
return None
|
| 112 |
+
if isinstance(file_obj, dict):
|
| 113 |
+
return file_obj.get("name") or file_obj.get("id")
|
| 114 |
+
# some SDKs return an object with .name or .id attributes
|
| 115 |
+
return getattr(file_obj, "name", None) or getattr(file_obj, "id", None) or getattr(file_obj, "fileId", None)
|
| 116 |
+
|
| 117 |
# configure GENAI if available
|
| 118 |
if API_KEY and HAS_GENAI:
|
| 119 |
try:
|
|
|
|
| 177 |
|
| 178 |
def wait_for_processed(file_obj, timeout=180):
|
| 179 |
start = time.time()
|
| 180 |
+
name = file_name_or_id(file_obj)
|
| 181 |
if not name:
|
| 182 |
return file_obj
|
| 183 |
while True:
|
|
|
|
| 210 |
else:
|
| 211 |
# fallback: call GENAI.responses.generate directly
|
| 212 |
with st.spinner("Generating description via SDK..."):
|
| 213 |
+
fname = file_name_or_id(processed)
|
| 214 |
+
if not fname:
|
| 215 |
+
raise RuntimeError("Uploaded file missing name/id")
|
| 216 |
+
|
| 217 |
request = {
|
| 218 |
"model": f"models/{model_id}",
|
| 219 |
+
"input": [{"text": prompt_text, "files": [{"name": fname}]}],
|
| 220 |
"safetySettings": safety_settings,
|
| 221 |
"maxOutputTokens": 1000,
|
| 222 |
}
|
| 223 |
res = GENAI.responses.generate(**request)
|
| 224 |
out = ""
|
| 225 |
# basic extraction
|
| 226 |
+
for item in (getattr(res, "output", None) or res.get("output", [])):
|
| 227 |
+
contents = getattr(item, "content", None) or item.get("content", [])
|
| 228 |
+
for c in contents:
|
| 229 |
+
ctype = getattr(c, "type", None) or c.get("type")
|
| 230 |
+
if ctype in ("output_text", "text"):
|
| 231 |
out += getattr(c, "text", "") or c.get("text", "")
|
| 232 |
if not out:
|
| 233 |
out = getattr(res, "text", None) or json.dumps(res, default=str)
|