Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,15 @@
|
|
| 1 |
import os
|
| 2 |
import validators
|
| 3 |
import streamlit as st
|
| 4 |
-
import json
|
| 5 |
-
import hashlib
|
| 6 |
-
from langchain.prompts import PromptTemplate
|
| 7 |
-
from langchain_groq import ChatGroq
|
| 8 |
-
from langchain.chains.summarize import load_summarize_chain
|
| 9 |
-
from langchain_community.document_loaders import YoutubeLoader, UnstructuredURLLoader
|
| 10 |
|
| 11 |
# Set page configuration FIRST
|
| 12 |
st.set_page_config(page_title="LangChain: Summarize Text From YT or Website", page_icon="🦜")
|
| 13 |
|
| 14 |
# Now import other modules
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Continue with the rest of your Streamlit App Setup
|
| 17 |
st.title("Last-Minute??? No Worries! Summarize Text From YT or Website :)")
|
|
@@ -39,31 +37,6 @@ Content:{text}
|
|
| 39 |
"""
|
| 40 |
prompt = PromptTemplate(template=prompt_template, input_variables=["text"])
|
| 41 |
|
| 42 |
-
# Define the path for storing the unique IP addresses
|
| 43 |
-
unique_viewers_file = "unique_viewers.json"
|
| 44 |
-
|
| 45 |
-
# Function to get the viewer's IP address (this is a placeholder; implement according to your deployment)
|
| 46 |
-
def get_viewer_ip():
|
| 47 |
-
# This is a mock IP for demonstration purposes
|
| 48 |
-
return hashlib.sha256(st.session_state["client_ip"].encode()).hexdigest()
|
| 49 |
-
|
| 50 |
-
# Load unique viewers data
|
| 51 |
-
if os.path.exists(unique_viewers_file):
|
| 52 |
-
with open(unique_viewers_file, "r") as f:
|
| 53 |
-
unique_viewers = json.load(f)
|
| 54 |
-
else:
|
| 55 |
-
unique_viewers = {}
|
| 56 |
-
|
| 57 |
-
# Track unique viewers
|
| 58 |
-
viewer_ip = get_viewer_ip()
|
| 59 |
-
if viewer_ip not in unique_viewers:
|
| 60 |
-
unique_viewers[viewer_ip] = 1
|
| 61 |
-
with open(unique_viewers_file, "w") as f:
|
| 62 |
-
json.dump(unique_viewers, f)
|
| 63 |
-
|
| 64 |
-
# Display the number of unique viewers
|
| 65 |
-
st.sidebar.write(f"Unique Viewers: {len(unique_viewers)}")
|
| 66 |
-
|
| 67 |
# Summarization Button Logic
|
| 68 |
if st.button("Summarize the Content from YT or Website"):
|
| 69 |
if not groq_api_key.strip() or not generic_url.strip():
|
|
@@ -90,4 +63,4 @@ if st.button("Summarize the Content from YT or Website"):
|
|
| 90 |
|
| 91 |
st.success(output_summary) # Display summarized output
|
| 92 |
except Exception as e:
|
| 93 |
-
st.exception(f"Exception: {e}")
|
|
|
|
| 1 |
import os
|
| 2 |
import validators
|
| 3 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Set page configuration FIRST
|
| 6 |
st.set_page_config(page_title="LangChain: Summarize Text From YT or Website", page_icon="🦜")
|
| 7 |
|
| 8 |
# Now import other modules
|
| 9 |
+
from langchain.prompts import PromptTemplate
|
| 10 |
+
from langchain_groq import ChatGroq
|
| 11 |
+
from langchain.chains.summarize import load_summarize_chain
|
| 12 |
+
from langchain_community.document_loaders import YoutubeLoader, UnstructuredURLLoader
|
| 13 |
|
| 14 |
# Continue with the rest of your Streamlit App Setup
|
| 15 |
st.title("Last-Minute??? No Worries! Summarize Text From YT or Website :)")
|
|
|
|
| 37 |
"""
|
| 38 |
prompt = PromptTemplate(template=prompt_template, input_variables=["text"])
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# Summarization Button Logic
|
| 41 |
if st.button("Summarize the Content from YT or Website"):
|
| 42 |
if not groq_api_key.strip() or not generic_url.strip():
|
|
|
|
| 63 |
|
| 64 |
st.success(output_summary) # Display summarized output
|
| 65 |
except Exception as e:
|
| 66 |
+
st.exception(f"Exception: {e}")
|