Update src/streamlit_app.py
Browse files- src/streamlit_app.py +17 -4
src/streamlit_app.py
CHANGED
|
@@ -34,7 +34,15 @@ logger = logging.getLogger(__name__)
|
|
| 34 |
|
| 35 |
def configure_gemini():
|
| 36 |
"""Configure Gemini API with backend key"""
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Enhanced system prompt with timestamp-based improvements
|
| 40 |
SYSTEM_PROMPT = f"""{os.getenv("SYS_PROMPT")}"""
|
|
@@ -57,7 +65,8 @@ def analyze_video_and_generate_script(
|
|
| 57 |
tmp_file_path = tmp_file.name
|
| 58 |
|
| 59 |
# Configure Gemini
|
| 60 |
-
configure_gemini()
|
|
|
|
| 61 |
|
| 62 |
# Show upload progress
|
| 63 |
upload_progress = st.progress(0)
|
|
@@ -121,8 +130,12 @@ def analyze_video_and_generate_script(
|
|
| 121 |
IMPORTANT: Return only valid JSON in the exact format specified in the system prompt. Analyze the video second-by-second for maximum detail."""
|
| 122 |
|
| 123 |
# Generate response
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
upload_progress.progress(100)
|
| 128 |
upload_status.success("Analysis complete!")
|
|
|
|
| 34 |
|
| 35 |
def configure_gemini():
|
| 36 |
"""Configure Gemini API with backend key"""
|
| 37 |
+
if not GEMINI_API_KEY:
|
| 38 |
+
st.error("GEMINI_KEY not found in environment variables")
|
| 39 |
+
return False
|
| 40 |
+
try:
|
| 41 |
+
genai.configure(api_key=GEMINI_API_KEY)
|
| 42 |
+
return True
|
| 43 |
+
except Exception as e:
|
| 44 |
+
st.error(f"Failed to configure Gemini API: {str(e)}")
|
| 45 |
+
return False
|
| 46 |
|
| 47 |
# Enhanced system prompt with timestamp-based improvements
|
| 48 |
SYSTEM_PROMPT = f"""{os.getenv("SYS_PROMPT")}"""
|
|
|
|
| 65 |
tmp_file_path = tmp_file.name
|
| 66 |
|
| 67 |
# Configure Gemini
|
| 68 |
+
if not configure_gemini():
|
| 69 |
+
return None
|
| 70 |
|
| 71 |
# Show upload progress
|
| 72 |
upload_progress = st.progress(0)
|
|
|
|
| 130 |
IMPORTANT: Return only valid JSON in the exact format specified in the system prompt. Analyze the video second-by-second for maximum detail."""
|
| 131 |
|
| 132 |
# Generate response
|
| 133 |
+
try:
|
| 134 |
+
model = genai.GenerativeModel("gemini-2.0-flash")
|
| 135 |
+
response = model.generate_content([video_file_obj, user_prompt + "\n\n" + SYSTEM_PROMPT])
|
| 136 |
+
except Exception as e:
|
| 137 |
+
st.error(f"Error generating content with Gemini: {str(e)}")
|
| 138 |
+
return None
|
| 139 |
|
| 140 |
upload_progress.progress(100)
|
| 141 |
upload_status.success("Analysis complete!")
|