Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- streamlit_app.py +22 -25
streamlit_app.py
CHANGED
|
@@ -193,9 +193,30 @@ def generate_report(video_path: Path, prompt: str, model_id: str, timeout: int =
|
|
| 193 |
video_part = {"inline_data": {"mime_type": "video/mp4", "data": b64}}
|
| 194 |
model = genai.GenerativeModel(model_name=model_id)
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
resp = model.generate_content(
|
| 197 |
[prompt, video_part],
|
| 198 |
-
generation_config={"max_output_tokens": 1024},
|
| 199 |
request_options={"timeout": timeout},
|
| 200 |
)
|
| 201 |
return getattr(resp, "text", str(resp))
|
|
@@ -345,30 +366,6 @@ if st.button("Run Analysis"):
|
|
| 345 |
st.error("No video loaded – load a video first.")
|
| 346 |
elif not st.session_state.get("api_key"):
|
| 347 |
st.error("Google API key missing – enter it in the sidebar.")
|
| 348 |
-
else:
|
| 349 |
-
# Configure Gemini model with safety settings
|
| 350 |
-
safety_settings = [
|
| 351 |
-
{
|
| 352 |
-
"category": "HARM_CATEGORY_HARASSMENT",
|
| 353 |
-
"threshold": "BLOCK_NONE"
|
| 354 |
-
},
|
| 355 |
-
{
|
| 356 |
-
"category": "HARM_CATEGORY_HATE_SPEECH",
|
| 357 |
-
"threshold": "BLOCK_NONE"
|
| 358 |
-
},
|
| 359 |
-
{
|
| 360 |
-
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
| 361 |
-
"threshold": "BLOCK_NONE"
|
| 362 |
-
},
|
| 363 |
-
{
|
| 364 |
-
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
| 365 |
-
"threshold": "BLOCK_NONE"
|
| 366 |
-
}
|
| 367 |
-
]
|
| 368 |
-
|
| 369 |
-
# Configure Gemini with API key and safety settings
|
| 370 |
-
genai.configure(api_key=st.session_state["api_key"],
|
| 371 |
-
safety_settings=safety_settings) # Set safety to lowest (none)
|
| 372 |
|
| 373 |
st.session_state["busy"] = True
|
| 374 |
st.session_state["analysis_out"] = ""
|
|
|
|
| 193 |
video_part = {"inline_data": {"mime_type": "video/mp4", "data": b64}}
|
| 194 |
model = genai.GenerativeModel(model_name=model_id)
|
| 195 |
|
| 196 |
+
# Adjust safety settings here
|
| 197 |
+
safety_settings = [
|
| 198 |
+
{
|
| 199 |
+
"category": "HARM_CATEGORY_HARASSMENT",
|
| 200 |
+
"threshold": "BLOCK_NONE"
|
| 201 |
+
},
|
| 202 |
+
{
|
| 203 |
+
"category": "HARM_CATEGORY_HATE_SPEECH",
|
| 204 |
+
"threshold": "BLOCK_NONE"
|
| 205 |
+
},
|
| 206 |
+
{
|
| 207 |
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
| 208 |
+
"threshold": "BLOCK_NONE"
|
| 209 |
+
},
|
| 210 |
+
{
|
| 211 |
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
| 212 |
+
"threshold": "BLOCK_NONE"
|
| 213 |
+
}
|
| 214 |
+
]
|
| 215 |
+
|
| 216 |
+
# Modify the generation request to include safety settings
|
| 217 |
resp = model.generate_content(
|
| 218 |
[prompt, video_part],
|
| 219 |
+
generation_config={"max_output_tokens": 1024, "safety_settings": safety_settings},
|
| 220 |
request_options={"timeout": timeout},
|
| 221 |
)
|
| 222 |
return getattr(resp, "text", str(resp))
|
|
|
|
| 366 |
st.error("No video loaded – load a video first.")
|
| 367 |
elif not st.session_state.get("api_key"):
|
| 368 |
st.error("Google API key missing – enter it in the sidebar.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
|
| 370 |
st.session_state["busy"] = True
|
| 371 |
st.session_state["analysis_out"] = ""
|