Dhaerie commited on
Commit
4e60a5d
Β·
verified Β·
1 Parent(s): 33361ea

Upload 3 files

Browse files
Files changed (3) hide show
  1. src/app.py +22 -0
  2. src/requirements.txt +0 -0
  3. src/utils.py +48 -0
src/app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from utils import generate_script
3
+
4
+ st.title("🎬 YouTube Script Generator (Hugging Face Version)")
5
+
6
+ prompt = st.text_input("Enter your video topic:")
7
+ video_length = st.slider("Video length (minutes):", 1, 20, 5)
8
+ creativity = st.slider("Creativity:", 0.0, 1.0, 0.7)
9
+
10
+ if st.button("Generate Script"):
11
+ with st.spinner("Generating script..."):
12
+ try:
13
+ search_result, title, script = generate_script(prompt, video_length, creativity)
14
+ st.success("βœ… Script Generated Successfully!")
15
+ st.subheader("🎯 Title:")
16
+ st.write(title)
17
+ st.subheader("πŸ” Search Data:")
18
+ st.write(search_result)
19
+ st.subheader("πŸ“ Script:")
20
+ st.write(script)
21
+ except Exception as e:
22
+ st.error(f"Error: {e}")
src/requirements.txt ADDED
Binary file (156 Bytes). View file
 
src/utils.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.llms import HuggingFaceHub
2
+ from langchain.prompts import PromptTemplate
3
+ from langchain.chains import LLMChain
4
+ from langchain_community.tools import DuckDuckGoSearchRun
5
+ import os
6
+
7
+
8
+ def generate_script(prompt, video_length, creativity):
9
+ """Generates a YouTube video script using a Hugging Face model (no OpenAI)."""
10
+
11
+ api_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
12
+ if not api_token:
13
+ raise ValueError("❌ Missing HUGGINGFACEHUB_API_TOKEN β€” please set it in Hugging Face Space Secrets.")
14
+
15
+ # βœ… Lightweight, free-tier-compatible model
16
+ llm = HuggingFaceHub(
17
+ repo_id="google/flan-t5-base",
18
+ model_kwargs={
19
+ "temperature": float(creativity),
20
+ "max_length": 512
21
+ }
22
+ )
23
+
24
+ title_template = PromptTemplate(
25
+ input_variables=["subject"],
26
+ template="Write a catchy YouTube video title about {subject}."
27
+ )
28
+
29
+ script_template = PromptTemplate(
30
+ input_variables=["title", "DuckDuckGo_Search", "duration"],
31
+ template=(
32
+ "Write a full YouTube video script for the title '{title}'. "
33
+ "The video should last about {duration} minutes. "
34
+ "Include relevant details based on this info: {DuckDuckGo_Search}."
35
+ )
36
+ )
37
+
38
+ title_chain = LLMChain(llm=llm, prompt=title_template)
39
+ script_chain = LLMChain(llm=llm, prompt=script_template)
40
+
41
+ search = DuckDuckGoSearchRun()
42
+
43
+ # Generate title and script
44
+ title = title_chain.run(prompt)
45
+ search_result = search.run(prompt)
46
+ script = script_chain.run(title=title, DuckDuckGo_Search=search_result, duration=video_length)
47
+
48
+ return search_result, title, script