Spaces:
Runtime error
Runtime error
File size: 2,754 Bytes
38b983a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
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("μ²λ¦¬ λ‘κ·Έ")
|