Spaces:
Sleeping
Sleeping
Update pages/model.py
Browse files- pages/model.py +10 -17
pages/model.py
CHANGED
|
@@ -6,14 +6,9 @@ from youtube_transcript_api import YouTubeTranscriptApi
|
|
| 6 |
from langchain_community.document_loaders import YoutubeLoader
|
| 7 |
from langchain_google_genai import GoogleGenerativeAI,ChatGoogleGenerativeAI
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
st.error("β Please set your Hugging Face API token in the environment as 'HF_Token'.")
|
| 13 |
-
st.stop()
|
| 14 |
-
else:
|
| 15 |
-
os.environ["HUGGINGFACEHUB_API_KEY"] = hf_token
|
| 16 |
-
os.environ["HF_TOKEN"] = hf_token
|
| 17 |
|
| 18 |
st.set_page_config(page_title="π¬ Tube2Insight", page_icon="π₯", layout="wide")
|
| 19 |
|
|
@@ -56,18 +51,19 @@ if st.button("π Summarize"):
|
|
| 56 |
with st.expander("π View Transcript"):
|
| 57 |
st.write(transcript)
|
| 58 |
|
| 59 |
-
llm =
|
| 60 |
-
|
| 61 |
-
|
|
|
|
| 62 |
)
|
| 63 |
-
|
| 64 |
prompt = ChatPromptTemplate.from_messages([
|
| 65 |
SystemMessagePromptTemplate.from_template("You are a helpful assistant summarizing YouTube transcripts."),
|
| 66 |
HumanMessagePromptTemplate.from_template("{transcript}")
|
| 67 |
])
|
| 68 |
messages = prompt.format_messages(transcript=transcript)
|
| 69 |
|
| 70 |
-
with st.spinner("π§ Summarizing with
|
| 71 |
response = llm.invoke(messages)
|
| 72 |
|
| 73 |
st.markdown("### π Summary")
|
|
@@ -75,9 +71,6 @@ if st.button("π Summarize"):
|
|
| 75 |
|
| 76 |
st.markdown("---")
|
| 77 |
st.markdown(
|
| 78 |
-
"<p style='text-align: center; color: gray;'>π Built with LangChain +
|
| 79 |
unsafe_allow_html=True
|
| 80 |
)
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
| 6 |
from langchain_community.document_loaders import YoutubeLoader
|
| 7 |
from langchain_google_genai import GoogleGenerativeAI,ChatGoogleGenerativeAI
|
| 8 |
|
| 9 |
+
from google.colab import userdata
|
| 10 |
+
gem=userdata.get('gemini')
|
| 11 |
+
os.environ["GOOGLE_API_KEY"]=gem
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
st.set_page_config(page_title="π¬ Tube2Insight", page_icon="π₯", layout="wide")
|
| 14 |
|
|
|
|
| 51 |
with st.expander("π View Transcript"):
|
| 52 |
st.write(transcript)
|
| 53 |
|
| 54 |
+
llm = ChatGoogleGenerativeAI(
|
| 55 |
+
model="gemini-2.0-flash",
|
| 56 |
+
temperature=0.5,
|
| 57 |
+
max_output_tokens=512
|
| 58 |
)
|
| 59 |
+
|
| 60 |
prompt = ChatPromptTemplate.from_messages([
|
| 61 |
SystemMessagePromptTemplate.from_template("You are a helpful assistant summarizing YouTube transcripts."),
|
| 62 |
HumanMessagePromptTemplate.from_template("{transcript}")
|
| 63 |
])
|
| 64 |
messages = prompt.format_messages(transcript=transcript)
|
| 65 |
|
| 66 |
+
with st.spinner("π§ Summarizing with Gemini 2.0 Flash..."):
|
| 67 |
response = llm.invoke(messages)
|
| 68 |
|
| 69 |
st.markdown("### π Summary")
|
|
|
|
| 71 |
|
| 72 |
st.markdown("---")
|
| 73 |
st.markdown(
|
| 74 |
+
"<p style='text-align: center; color: gray;'>π Built with LangChain + Gemini + Streamlit </p>",
|
| 75 |
unsafe_allow_html=True
|
| 76 |
)
|
|
|
|
|
|
|
|
|