Spaces:
Runtime error
Runtime error
import streamlit as st | |
from pytubefix import YouTube | |
from pytubefix.cli import on_progress | |
import google.generativeai as genai | |
import time | |
import os | |
# Gemini API ν€ μ€μ | |
genai.configure(api_key=os.environ["GOOGLE_API_KEY"]) | |
def process_video(url): | |
with st.spinner("λμμ μ²λ¦¬ μ€..."): | |
yt = YouTube(url, on_progress_callback=on_progress) | |
st.sidebar.info(f"μ λͺ©: {yt.title}") | |
video_file_name = "video.mp4" | |
ys = yt.streams.get_lowest_resolution() | |
ys.download(filename=video_file_name) | |
st.sidebar.info("μ νλΈ λμμ λ€μ΄λ‘λ μλ£") | |
video_file = genai.upload_file(path=video_file_name) | |
st.sidebar.info(f"generativeaiμ λμμ μ λ‘λ μλ£") | |
while video_file.state.name == "PROCESSING": | |
st.sidebar.info("μ²λ¦¬ μ€...") | |
time.sleep(10) | |
video_file = genai.get_file(video_file.name) | |
if video_file.state.name == "FAILED": | |
raise ValueError(video_file.state.name) | |
prompt = "μ΄ λμμμ μμ½ν©λλ€. μ£Όμ λ΄μ©μ 5κ°μ bullet pointλ‘ μ 리νκ³ , κ·Έ μλμ μμΈν μμ½μ μ 곡ν΄μ£ΌμΈμ." | |
model = genai.GenerativeModel(model_name="gemini-1.5-pro") | |
st.sidebar.info("AI λͺ¨λΈμ΄ λμμμ λΆμ μ€...") | |
response = model.generate_content( | |
[video_file, prompt], request_options={"timeout": 600} | |
) | |
genai.delete_file(video_file.name) | |
st.sidebar.info("μμ νμΌ μμ μλ£") | |
os.remove(video_file_name) | |
st.sidebar.info("μμ λΉλμ€ νμΌ μμ μλ£") | |
return response.text | |
st.set_page_config(page_title="μ νλΈ λμμ μμ½ μ±", layout="wide") | |
st.title("π₯ μ νλΈ λμμ μμ½ μ±") | |
url = st.text_input("μ νλΈ URLμ μ λ ₯νμΈμ:") | |
if st.button("μμ½νκΈ°", key="summarize"): | |
if url: | |
try: | |
summary = process_video(url) | |
st.success("μμ½μ΄ μλ£λμμ΅λλ€!") | |
# μμ½ κ²°κ³Ό νμ | |
st.header("π μμ½ κ²°κ³Ό") | |
# μ£Όμ λ΄μ© (bullet points) | |
st.subheader("μ£Όμ λ΄μ©") | |
bullet_points = summary.split("\n\n")[0].split("\n")[1:] | |
for point in bullet_points: | |
st.markdown(f"- {point.strip()}") | |
# μμΈ μμ½ | |
st.subheader("μμΈ μμ½") | |
detailed_summary = "\n\n".join(summary.split("\n\n")[1:]) | |
st.markdown(detailed_summary) | |
except Exception as e: | |
st.error(f"μ€λ₯ λ°μ: {str(e)}") | |
else: | |
st.warning("URLμ μ λ ₯ν΄μ£ΌμΈμ.") | |
# μ¬μ΄λλ°μ λ‘κ·Έ μ 보 νμ | |
st.sidebar.title("μ²λ¦¬ λ‘κ·Έ") | |