Update src/streamlit_app.py
Browse files- src/streamlit_app.py +7 -19
src/streamlit_app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
import tempfile
|
| 4 |
import os
|
| 5 |
import time
|
|
@@ -34,7 +34,7 @@ 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 +57,7 @@ def analyze_video_and_generate_script(
|
|
| 57 |
tmp_file_path = tmp_file.name
|
| 58 |
|
| 59 |
# Configure Gemini
|
| 60 |
-
|
| 61 |
|
| 62 |
# Show upload progress
|
| 63 |
upload_progress = st.progress(0)
|
|
@@ -67,13 +67,13 @@ def analyze_video_and_generate_script(
|
|
| 67 |
upload_progress.progress(20)
|
| 68 |
|
| 69 |
# Upload video to Gemini
|
| 70 |
-
video_file_obj =
|
| 71 |
upload_progress.progress(40)
|
| 72 |
|
| 73 |
upload_status.text("Processing video...")
|
| 74 |
while video_file_obj.state.name == "PROCESSING":
|
| 75 |
time.sleep(2)
|
| 76 |
-
video_file_obj =
|
| 77 |
upload_progress.progress(60)
|
| 78 |
|
| 79 |
if video_file_obj.state.name == "FAILED":
|
|
@@ -121,10 +121,8 @@ 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 |
-
contents=[video_file_obj, user_prompt + "\n\n" + SYSTEM_PROMPT]
|
| 127 |
-
)
|
| 128 |
|
| 129 |
upload_progress.progress(100)
|
| 130 |
upload_status.success("Analysis complete!")
|
|
@@ -341,16 +339,6 @@ def check_token(user_token):
|
|
| 341 |
def main():
|
| 342 |
"""Main application function"""
|
| 343 |
|
| 344 |
-
st.set_page_config(
|
| 345 |
-
page_title="Video Analyser and Script Generator",
|
| 346 |
-
page_icon="🎥",
|
| 347 |
-
layout="wide",
|
| 348 |
-
initial_sidebar_state="expanded"
|
| 349 |
-
)
|
| 350 |
-
|
| 351 |
-
st.title("Video Analyser and Script Generator")
|
| 352 |
-
st.divider()
|
| 353 |
-
|
| 354 |
if "authenticated" not in st.session_state:
|
| 355 |
st.session_state["authenticated"] = False
|
| 356 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
import tempfile
|
| 4 |
import os
|
| 5 |
import time
|
|
|
|
| 34 |
|
| 35 |
def configure_gemini():
|
| 36 |
"""Configure Gemini API with backend key"""
|
| 37 |
+
genai.configure(api_key=GEMINI_API_KEY)
|
| 38 |
|
| 39 |
# Enhanced system prompt with timestamp-based improvements
|
| 40 |
SYSTEM_PROMPT = f"""{os.getenv("SYS_PROMPT")}"""
|
|
|
|
| 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)
|
|
|
|
| 67 |
upload_progress.progress(20)
|
| 68 |
|
| 69 |
# Upload video to Gemini
|
| 70 |
+
video_file_obj = genai.upload_file(tmp_file_path)
|
| 71 |
upload_progress.progress(40)
|
| 72 |
|
| 73 |
upload_status.text("Processing video...")
|
| 74 |
while video_file_obj.state.name == "PROCESSING":
|
| 75 |
time.sleep(2)
|
| 76 |
+
video_file_obj = genai.get_file(video_file_obj.name)
|
| 77 |
upload_progress.progress(60)
|
| 78 |
|
| 79 |
if video_file_obj.state.name == "FAILED":
|
|
|
|
| 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 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 125 |
+
response = model.generate_content([video_file_obj, user_prompt + "\n\n" + SYSTEM_PROMPT])
|
|
|
|
|
|
|
| 126 |
|
| 127 |
upload_progress.progress(100)
|
| 128 |
upload_status.success("Analysis complete!")
|
|
|
|
| 339 |
def main():
|
| 340 |
"""Main application function"""
|
| 341 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
if "authenticated" not in st.session_state:
|
| 343 |
st.session_state["authenticated"] = False
|
| 344 |
|