Spaces:
Running
Running
Upload 11 files
Browse files- .gitattributes +6 -0
- chatgskd.png +3 -0
- chatgskd.py +61 -0
- generate.png +3 -0
- google.png +3 -0
- google.py +136 -0
- news.png +3 -0
- news.py +224 -0
- wikipedia.png +3 -0
- wikipedia.py +137 -0
- youtube.png +3 -0
- youtube.py +87 -0
.gitattributes
CHANGED
@@ -33,3 +33,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
chatgskd.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
generate.png filter=lfs diff=lfs merge=lfs -text
|
38 |
+
google.png filter=lfs diff=lfs merge=lfs -text
|
39 |
+
news.png filter=lfs diff=lfs merge=lfs -text
|
40 |
+
wikipedia.png filter=lfs diff=lfs merge=lfs -text
|
41 |
+
youtube.png filter=lfs diff=lfs merge=lfs -text
|
chatgskd.png
ADDED
![]() |
Git LFS Details
|
chatgskd.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Load API Key from Hugging Face Secrets
|
6 |
+
HF_API_KEY = os.getenv("KEY")
|
7 |
+
|
8 |
+
# API URL
|
9 |
+
HF_MISTRAL_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3"
|
10 |
+
|
11 |
+
# Function to call Hugging Face API
|
12 |
+
def chat_with_mistral_hf(prompt):
|
13 |
+
if not HF_API_KEY:
|
14 |
+
return "Error: API key not found. Please set it in Hugging Face Secrets."
|
15 |
+
|
16 |
+
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
|
17 |
+
payload = {"inputs": prompt, "parameters": {"max_length": 200, "temperature": 0.7}}
|
18 |
+
|
19 |
+
response = requests.post(HF_MISTRAL_URL, json=payload, headers=headers)
|
20 |
+
|
21 |
+
if response.status_code == 200:
|
22 |
+
return response.json()[0]["generated_text"]
|
23 |
+
else:
|
24 |
+
return f"Error: {response.json()}"
|
25 |
+
|
26 |
+
# Streamlit UI
|
27 |
+
st.set_page_config(page_title="ChatGSKD", layout="wide")
|
28 |
+
|
29 |
+
# Sidebar: Chat title rename option
|
30 |
+
st.sidebar.header("Chat Settings")
|
31 |
+
chat_title = st.sidebar.text_input("Rename Chat:", "Temporary Chat")
|
32 |
+
|
33 |
+
# Initialize chat history if not present
|
34 |
+
if "chat_history" not in st.session_state:
|
35 |
+
st.session_state.chat_history = []
|
36 |
+
|
37 |
+
# Display Chat Title
|
38 |
+
st.title(chat_title)
|
39 |
+
|
40 |
+
# Show chat history
|
41 |
+
for chat in st.session_state.chat_history:
|
42 |
+
with st.chat_message(chat["role"]):
|
43 |
+
st.write(chat["content"])
|
44 |
+
|
45 |
+
# Input box at the bottom
|
46 |
+
user_input = st.text_area("Ask AI:", height=100, key="query", label_visibility="collapsed")
|
47 |
+
|
48 |
+
# Generate response when user submits a prompt
|
49 |
+
if st.button("Generate Response"):
|
50 |
+
if user_input.strip():
|
51 |
+
with st.spinner("Generating response..."):
|
52 |
+
response = chat_with_mistral_hf(user_input)
|
53 |
+
|
54 |
+
# Store user query & response in chat history
|
55 |
+
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
56 |
+
st.session_state.chat_history.append({"role": "assistant", "content": response})
|
57 |
+
|
58 |
+
# Refresh the page to show new messages
|
59 |
+
st.rerun()
|
60 |
+
else:
|
61 |
+
st.warning("Please enter a prompt before clicking Generate Response.")
|
generate.png
ADDED
![]() |
Git LFS Details
|
google.png
ADDED
![]() |
Git LFS Details
|
google.py
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
import speech_recognition as sr
|
6 |
+
import pandas as pd
|
7 |
+
import altair as alt
|
8 |
+
from PIL import Image
|
9 |
+
from io import BytesIO
|
10 |
+
|
11 |
+
# Function to perform Google Search
|
12 |
+
def google_search(api_key, cse_id, query, num_results=10):
|
13 |
+
url = "https://www.googleapis.com/customsearch/v1"
|
14 |
+
params = {'key': api_key, 'cx': cse_id, 'q': query, 'num': num_results}
|
15 |
+
response = requests.get(url, params=params)
|
16 |
+
return response.json()
|
17 |
+
|
18 |
+
# Initialize search history and data storage for analytics
|
19 |
+
if 'search_history' not in st.session_state:
|
20 |
+
st.session_state.search_history = []
|
21 |
+
if 'search_data' not in st.session_state:
|
22 |
+
st.session_state.search_data = pd.DataFrame(columns=["Query", "Source", "Timestamp"])
|
23 |
+
|
24 |
+
def main():
|
25 |
+
st.title("Enhanced Google Search Application")
|
26 |
+
|
27 |
+
# User inputs for API key, CSE ID, and search query
|
28 |
+
api_key = "AIzaSyBvnTpjwspsYBMlHN4nMEvybEmZL8mwAQ4"
|
29 |
+
cse_id = "464947c4e602c4ee8"
|
30 |
+
query = st.text_input("Enter your search query", "", key='query_input')
|
31 |
+
|
32 |
+
# Voice search feature
|
33 |
+
if st.button("Use Voice Search"):
|
34 |
+
recognizer = sr.Recognizer()
|
35 |
+
with sr.Microphone() as source:
|
36 |
+
st.write("Listening...")
|
37 |
+
audio = recognizer.listen(source)
|
38 |
+
try:
|
39 |
+
query = recognizer.recognize_google(audio)
|
40 |
+
st.write(f"You said: {query}")
|
41 |
+
if api_key and cse_id and query:
|
42 |
+
results = google_search(api_key, cse_id, query)
|
43 |
+
update_search_history(query, "Voice")
|
44 |
+
display_results(results)
|
45 |
+
except sr.UnknownValueError:
|
46 |
+
st.error("Could not understand audio.")
|
47 |
+
except sr.RequestError:
|
48 |
+
st.error("Could not request results from Google.")
|
49 |
+
|
50 |
+
# Trigger search on Enter or when search button is clicked
|
51 |
+
if st.button("Search") or st.session_state.get('query_input'):
|
52 |
+
if api_key and cse_id and query:
|
53 |
+
results = google_search(api_key, cse_id, query)
|
54 |
+
update_search_history(query, "Text")
|
55 |
+
display_results(results)
|
56 |
+
else:
|
57 |
+
st.error("Please enter API Key, CSE ID, and a search query.")
|
58 |
+
|
59 |
+
# Button to show search history
|
60 |
+
if st.button("Show Search History"):
|
61 |
+
if st.session_state.search_history:
|
62 |
+
st.write("Search History:")
|
63 |
+
for h in st.session_state.search_history:
|
64 |
+
st.write(h)
|
65 |
+
else:
|
66 |
+
st.write("No search history found.")
|
67 |
+
|
68 |
+
# Button to clear search history
|
69 |
+
if st.button("Clear Search History"):
|
70 |
+
st.session_state.search_history.clear()
|
71 |
+
st.session_state.search_data = pd.DataFrame(columns=["Query", "Source", "Timestamp"])
|
72 |
+
st.success("Search history cleared.")
|
73 |
+
|
74 |
+
# Interactive Analytics Dashboard
|
75 |
+
st.subheader("Search Analytics")
|
76 |
+
if not st.session_state.search_data.empty:
|
77 |
+
# Chart of search counts over time
|
78 |
+
search_trends = alt.Chart(st.session_state.search_data).mark_line().encode(
|
79 |
+
x='Timestamp:T',
|
80 |
+
y='count():Q',
|
81 |
+
color='Source:N',
|
82 |
+
tooltip=['Query:N', 'count():Q', 'Source:N']
|
83 |
+
).properties(width=600, height=300)
|
84 |
+
st.altair_chart(search_trends, use_container_width=True)
|
85 |
+
|
86 |
+
# Most popular queries
|
87 |
+
st.write("**Top Search Queries**")
|
88 |
+
top_queries = (
|
89 |
+
st.session_state.search_data['Query']
|
90 |
+
.value_counts()
|
91 |
+
.head(5)
|
92 |
+
.reset_index()
|
93 |
+
.rename(columns={'index': 'Query', 'Query': 'Count'})
|
94 |
+
)
|
95 |
+
st.write(top_queries)
|
96 |
+
|
97 |
+
def display_results(results):
|
98 |
+
if results and 'items' in results:
|
99 |
+
st.session_state.results = results
|
100 |
+
for i, item in enumerate(results['items']):
|
101 |
+
st.write(f"**{i + 1}. {item['title']}**")
|
102 |
+
st.write(f"[Link]({item['link']})")
|
103 |
+
st.write(f"{item['snippet']}\n")
|
104 |
+
|
105 |
+
# Check if 'pagemap' and 'cse_image' exist and if 'src' is in 'cse_image'
|
106 |
+
if 'pagemap' in item and 'cse_image' in item['pagemap']:
|
107 |
+
image_data = item['pagemap']['cse_image'][0]
|
108 |
+
image_url = image_data.get('src') # Use .get() to avoid KeyError
|
109 |
+
|
110 |
+
# Try to load and display the image if 'src' exists
|
111 |
+
if image_url:
|
112 |
+
try:
|
113 |
+
response = requests.get(image_url)
|
114 |
+
img = Image.open(BytesIO(response.content))
|
115 |
+
st.image(img, width=100)
|
116 |
+
except Exception as e:
|
117 |
+
st.write("**Image could not be loaded.**")
|
118 |
+
else:
|
119 |
+
st.write("**Image source not available.**")
|
120 |
+
else:
|
121 |
+
st.write("No image available for this result.")
|
122 |
+
else:
|
123 |
+
st.write("No results found.")
|
124 |
+
|
125 |
+
def update_search_history(query, source):
|
126 |
+
# Update search history and analytics data
|
127 |
+
st.session_state.search_history.append(query)
|
128 |
+
new_data = pd.DataFrame({
|
129 |
+
"Query": [query],
|
130 |
+
"Source": [source],
|
131 |
+
"Timestamp": [pd.Timestamp.now()]
|
132 |
+
})
|
133 |
+
st.session_state.search_data = pd.concat([st.session_state.search_data, new_data], ignore_index=True)
|
134 |
+
|
135 |
+
if __name__ == "__main__":
|
136 |
+
main()
|
news.png
ADDED
![]() |
Git LFS Details
|
news.py
ADDED
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import pandas as pd
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
from datetime import datetime, timedelta
|
6 |
+
|
7 |
+
# Set page configuration
|
8 |
+
st.set_page_config(page_title="News Fetcher", layout="wide")
|
9 |
+
|
10 |
+
# CSS styling for Canva theme
|
11 |
+
st.markdown(
|
12 |
+
"""
|
13 |
+
<style>
|
14 |
+
/* General styling */
|
15 |
+
body {
|
16 |
+
font-family: 'Helvetica Neue', Arial, sans-serif;
|
17 |
+
background-color: #f8f9fa; /* Light gray background */
|
18 |
+
color: #333; /* Dark gray font color */
|
19 |
+
}
|
20 |
+
|
21 |
+
/* Title styling */
|
22 |
+
h1 {
|
23 |
+
color: #00bcd4; /* Canva teal */
|
24 |
+
font-size: 2.5em;
|
25 |
+
margin-bottom: 0.5em;
|
26 |
+
}
|
27 |
+
|
28 |
+
/* Sidebar styling */
|
29 |
+
.css-18e3th9 {
|
30 |
+
background-color: #ffffff; /* White background for sidebar */
|
31 |
+
color: #333; /* Dark text color */
|
32 |
+
border-right: 1px solid #e0e0e0; /* Light gray border */
|
33 |
+
padding: 20px;
|
34 |
+
}
|
35 |
+
|
36 |
+
/* Sidebar header */
|
37 |
+
.css-hxt7ib {
|
38 |
+
color: #00bcd4; /* Canva teal */
|
39 |
+
font-weight: bold;
|
40 |
+
}
|
41 |
+
|
42 |
+
/* Button styling */
|
43 |
+
button {
|
44 |
+
background-color: #00bcd4 !important; /* Canva teal button */
|
45 |
+
color: white !important;
|
46 |
+
border: none !important;
|
47 |
+
font-weight: bold !important;
|
48 |
+
padding: 10px 20px;
|
49 |
+
border-radius: 5px;
|
50 |
+
}
|
51 |
+
|
52 |
+
/* Dropdown and input styling */
|
53 |
+
.stTextInput, .stDateInput, .stSelectbox {
|
54 |
+
border: 1px solid #e0e0e0 !important; /* Light gray border */
|
55 |
+
border-radius: 5px !important;
|
56 |
+
padding: 10px !important;
|
57 |
+
font-size: 1em !important;
|
58 |
+
}
|
59 |
+
|
60 |
+
/* News articles styling */
|
61 |
+
.stMarkdown, .stSubheader {
|
62 |
+
font-family: 'Helvetica Neue', Arial, sans-serif;
|
63 |
+
background-color: #ffffff; /* White background for articles */
|
64 |
+
color: #212529; /* Darker gray for articles text */
|
65 |
+
padding: 15px;
|
66 |
+
border-radius: 8px;
|
67 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
68 |
+
}
|
69 |
+
|
70 |
+
/* Footer styling */
|
71 |
+
footer {
|
72 |
+
font-size: 0.85em;
|
73 |
+
color: #6c757d; /* Gray footer text */
|
74 |
+
text-align: center;
|
75 |
+
margin-top: 50px;
|
76 |
+
padding: 10px;
|
77 |
+
border-top: 1px solid #e0e0e0;
|
78 |
+
}
|
79 |
+
|
80 |
+
/* Link styling */
|
81 |
+
a {
|
82 |
+
color: #00bcd4; /* Canva teal */
|
83 |
+
}
|
84 |
+
|
85 |
+
a:hover {
|
86 |
+
color: #0097a7; /* Darker teal on hover */
|
87 |
+
}
|
88 |
+
</style>
|
89 |
+
""",
|
90 |
+
unsafe_allow_html=True
|
91 |
+
)
|
92 |
+
|
93 |
+
# Define countries dictionary
|
94 |
+
countries = {
|
95 |
+
'us': 'United States',
|
96 |
+
'in': 'India',
|
97 |
+
'gb': 'United Kingdom',
|
98 |
+
'ca': 'Canada',
|
99 |
+
'au': 'Australia',
|
100 |
+
'de': 'Germany',
|
101 |
+
'fr': 'France',
|
102 |
+
'it': 'Italy',
|
103 |
+
'jp': 'Japan',
|
104 |
+
'cn': 'China',
|
105 |
+
'br': 'Brazil',
|
106 |
+
'za': 'South Africa',
|
107 |
+
'ru': 'Russia',
|
108 |
+
}
|
109 |
+
|
110 |
+
def get_news(api_key, query=None, country='us', language='en', from_date=None, to_date=None):
|
111 |
+
url = 'https://newsapi.org/v2/everything'
|
112 |
+
params = {
|
113 |
+
'apiKey': api_key,
|
114 |
+
'q': query,
|
115 |
+
'from': from_date,
|
116 |
+
'to': to_date,
|
117 |
+
'language': language,
|
118 |
+
'pageSize': 20
|
119 |
+
}
|
120 |
+
|
121 |
+
try:
|
122 |
+
response = requests.get(url, params=params)
|
123 |
+
response.raise_for_status()
|
124 |
+
news_data = response.json()
|
125 |
+
if news_data['status'] == 'ok':
|
126 |
+
return news_data['articles']
|
127 |
+
else:
|
128 |
+
st.error("Error fetching news: {}".format(news_data['message']))
|
129 |
+
return []
|
130 |
+
|
131 |
+
except requests.exceptions.RequestException as e:
|
132 |
+
st.error("HTTP Request failed: {}".format(e))
|
133 |
+
return []
|
134 |
+
|
135 |
+
# Important queries
|
136 |
+
important_queries = [
|
137 |
+
"COVID-19", "Technology", "Politics", "Economy", "Health",
|
138 |
+
"Environment", "Sports", "Entertainment", "Science",
|
139 |
+
"Education", "Travel"
|
140 |
+
]
|
141 |
+
|
142 |
+
# Streamlit UI setup
|
143 |
+
st.title("News Fetcher")
|
144 |
+
|
145 |
+
# Store and display the last seen timestamp
|
146 |
+
if 'last_seen' not in st.session_state:
|
147 |
+
st.session_state['last_seen'] = datetime.now()
|
148 |
+
else:
|
149 |
+
st.session_state['last_seen'] = datetime.now()
|
150 |
+
last_seen = st.session_state['last_seen']
|
151 |
+
|
152 |
+
# Sidebar layout
|
153 |
+
st.sidebar.title("Settings")
|
154 |
+
st.sidebar.write(f"Last accessed on: {last_seen.strftime('%Y-%m-%d %H:%M:%S')}")
|
155 |
+
|
156 |
+
# Language selection
|
157 |
+
language = st.selectbox("Select your preferred language:",
|
158 |
+
options=[
|
159 |
+
('en', 'English'), ('es', 'Spanish'), ('fr', 'French'),
|
160 |
+
('de', 'German'), ('it', 'Italian'), ('pt', 'Portuguese'),
|
161 |
+
('ar', 'Arabic'), ('zh', 'Chinese'), ('hi', 'Hindi'),
|
162 |
+
('te', 'Telugu')
|
163 |
+
])
|
164 |
+
|
165 |
+
# Country selection in the sidebar
|
166 |
+
country = st.sidebar.selectbox("Select your country:", options=list(countries.keys()), format_func=lambda x: countries[x])
|
167 |
+
|
168 |
+
# Sidebar for important queries
|
169 |
+
st.sidebar.header("Important Queries")
|
170 |
+
for query in important_queries:
|
171 |
+
if st.sidebar.button(query):
|
172 |
+
st.session_state.query = query
|
173 |
+
|
174 |
+
# Input field for user queries
|
175 |
+
if 'query' in st.session_state:
|
176 |
+
query = st.session_state.query
|
177 |
+
else:
|
178 |
+
query = st.text_input("Enter a search query:", placeholder="Type something...")
|
179 |
+
|
180 |
+
# Date pickers for filtering news articles
|
181 |
+
st.write("Select the date range for previous news articles:")
|
182 |
+
from_date = st.date_input("From", value=datetime.now() - timedelta(days=30))
|
183 |
+
to_date = st.date_input("To", value=datetime.now())
|
184 |
+
|
185 |
+
# Button to fetch news
|
186 |
+
if st.button("Fetch News"):
|
187 |
+
API_KEY = '43283de608cc43b7a49ad17ceda39636' # Replace with your actual News API key
|
188 |
+
news_articles = get_news(API_KEY, query=query, country=country, language=language, from_date=from_date, to_date=to_date)
|
189 |
+
|
190 |
+
if news_articles:
|
191 |
+
for i, article in enumerate(news_articles):
|
192 |
+
st.subheader(article['title'])
|
193 |
+
st.markdown(f"**Source**: {article['source']['name']} | **Published At**: {article['publishedAt']}")
|
194 |
+
st.write(article['description'] or "No description available")
|
195 |
+
st.markdown(f"[Read more]({article['url']})")
|
196 |
+
st.markdown("---")
|
197 |
+
|
198 |
+
# Visualization of trends in news topics
|
199 |
+
dates = [article['publishedAt'][:10] for article in news_articles]
|
200 |
+
date_counts = pd.Series(dates).value_counts().sort_index()
|
201 |
+
|
202 |
+
st.subheader("Trends in News Topics Over Time")
|
203 |
+
plt.figure(figsize=(10, 5))
|
204 |
+
plt.plot(date_counts.index, date_counts.values, marker='o')
|
205 |
+
plt.xticks(rotation=45)
|
206 |
+
plt.xlabel('Date')
|
207 |
+
plt.ylabel('Number of Articles')
|
208 |
+
plt.title('Frequency of Articles Over Time')
|
209 |
+
st.pyplot(plt)
|
210 |
+
|
211 |
+
else:
|
212 |
+
st.write("No articles found.")
|
213 |
+
|
214 |
+
# Footer
|
215 |
+
st.markdown("---")
|
216 |
+
st.markdown(
|
217 |
+
"""
|
218 |
+
<footer>
|
219 |
+
Developed by SriKrishna | © 2024 | All rights reserved.<br>
|
220 |
+
Last accessed on: {}
|
221 |
+
</footer>
|
222 |
+
""".format(last_seen.strftime('%Y-%m-%d %H:%M:%S')),
|
223 |
+
unsafe_allow_html=True
|
224 |
+
)
|
wikipedia.png
ADDED
![]() |
Git LFS Details
|
wikipedia.py
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import wikipediaapi
|
3 |
+
import datetime
|
4 |
+
from reportlab.lib.pagesizes import letter
|
5 |
+
from reportlab.pdfgen import canvas
|
6 |
+
import tempfile
|
7 |
+
from gtts import gTTS
|
8 |
+
import speech_recognition as sr
|
9 |
+
|
10 |
+
# Wikipedia summary function with character limit and summary levels
|
11 |
+
def get_wikipedia_summary(query, lang_code, char_limit, summary_level):
|
12 |
+
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"
|
13 |
+
wiki = wikipediaapi.Wikipedia(language=lang_code, extract_format=wikipediaapi.ExtractFormat.WIKI, user_agent=user_agent)
|
14 |
+
page = wiki.page(query)
|
15 |
+
if not page.exists():
|
16 |
+
return "Page not found."
|
17 |
+
if summary_level == "Brief":
|
18 |
+
return page.summary[:char_limit]
|
19 |
+
elif summary_level == "Detailed":
|
20 |
+
return page.summary # Full summary
|
21 |
+
elif summary_level == "Bullet Points":
|
22 |
+
points = page.summary.split('. ')
|
23 |
+
return '\n'.join(f"- {p.strip()}" for p in points if p)[:char_limit]
|
24 |
+
|
25 |
+
# Save chat history as PDF with a user-defined filename
|
26 |
+
def save_chat_history_as_pdf(chat_history, file_name):
|
27 |
+
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
28 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file:
|
29 |
+
pdf = canvas.Canvas(tmp_file.name, pagesize=letter)
|
30 |
+
pdf.setTitle(file_name)
|
31 |
+
pdf.drawString(30, 750, f"{file_name} - Saved on {timestamp}")
|
32 |
+
y_position = 720
|
33 |
+
for query, response in chat_history:
|
34 |
+
pdf.drawString(30, y_position, f"User: {query}")
|
35 |
+
y_position -= 20
|
36 |
+
pdf.drawString(30, y_position, f"Bot: {response}")
|
37 |
+
y_position -= 40
|
38 |
+
if y_position < 40:
|
39 |
+
pdf.showPage()
|
40 |
+
y_position = 750
|
41 |
+
pdf.save()
|
42 |
+
return tmp_file.name
|
43 |
+
|
44 |
+
# Text-to-speech using gTTS
|
45 |
+
def text_to_speech(text, filename, lang="en"):
|
46 |
+
tts = gTTS(text=text, lang=lang)
|
47 |
+
tts.save(filename)
|
48 |
+
return filename
|
49 |
+
|
50 |
+
# Voice search function
|
51 |
+
def voice_search(lang_code):
|
52 |
+
recognizer = sr.Recognizer()
|
53 |
+
with sr.Microphone() as source:
|
54 |
+
st.write("Listening...")
|
55 |
+
audio = recognizer.listen(source)
|
56 |
+
try:
|
57 |
+
# Recognize the speech based on the specified language
|
58 |
+
query = recognizer.recognize_google(audio, language=lang_code)
|
59 |
+
st.success(f"You said: {query}")
|
60 |
+
return query
|
61 |
+
except sr.UnknownValueError:
|
62 |
+
st.error("Sorry, I could not understand the audio.")
|
63 |
+
return None
|
64 |
+
except sr.RequestError as e:
|
65 |
+
st.error(f"Could not request results from Google Speech Recognition service; {e}")
|
66 |
+
return None
|
67 |
+
|
68 |
+
# Initialize the Streamlit app
|
69 |
+
def main():
|
70 |
+
st.set_page_config(page_title="Wikipedia Summary & Text-to-Speech", layout="wide")
|
71 |
+
|
72 |
+
# Sidebar options
|
73 |
+
st.sidebar.title("Options")
|
74 |
+
lang_map = {
|
75 |
+
"English": "en",
|
76 |
+
"Spanish": "es",
|
77 |
+
"Chinese": "zh",
|
78 |
+
"Hindi": "hi",
|
79 |
+
"Telugu": "te"
|
80 |
+
}
|
81 |
+
selected_lang = st.sidebar.selectbox("Wikipedia Language", list(lang_map.keys()), key="language_selector")
|
82 |
+
summary_levels = ["Brief", "Detailed", "Bullet Points"]
|
83 |
+
summary_level = st.sidebar.selectbox("Summarization Level", summary_levels)
|
84 |
+
char_limit = st.sidebar.slider("Character Limit", min_value=100, max_value=2000, value=500, step=100)
|
85 |
+
|
86 |
+
# Chat history and favorites in session state
|
87 |
+
if "chat_history" not in st.session_state:
|
88 |
+
st.session_state.chat_history = []
|
89 |
+
if "favorites" not in st.session_state:
|
90 |
+
st.session_state.favorites = []
|
91 |
+
|
92 |
+
st.title("Wikipedia Summary & Text-to-Speech")
|
93 |
+
|
94 |
+
# Text input for manual search
|
95 |
+
query = st.text_input("Enter a topic to search on Wikipedia:")
|
96 |
+
|
97 |
+
# Button for voice search
|
98 |
+
if st.button("Voice Search"):
|
99 |
+
lang_code = lang_map[selected_lang] # Get the language code for the selected language
|
100 |
+
voice_query = voice_search(lang_code) # Pass the language code to the voice search
|
101 |
+
if voice_query:
|
102 |
+
query = voice_query # Use the voice query if recognized
|
103 |
+
|
104 |
+
# Display summary based on query and language selection
|
105 |
+
if query:
|
106 |
+
lang_code = lang_map[selected_lang]
|
107 |
+
summary = get_wikipedia_summary(query, lang_code, char_limit, summary_level)
|
108 |
+
st.markdown(f"### Summary for: {query}")
|
109 |
+
st.write(summary)
|
110 |
+
st.session_state.chat_history.append((query, summary))
|
111 |
+
|
112 |
+
# Save to favorites
|
113 |
+
if st.button("Add to Favorites"):
|
114 |
+
st.session_state.favorites.append((query, summary))
|
115 |
+
st.success("Added to favorites!")
|
116 |
+
|
117 |
+
# Text-to-speech
|
118 |
+
tts_filename = f"{query}_speech.mp3"
|
119 |
+
if st.button("Play Text-to-Speech"):
|
120 |
+
text_to_speech(summary, tts_filename, lang=lang_code)
|
121 |
+
st.audio(tts_filename, format="audio/mp3")
|
122 |
+
|
123 |
+
# Save chat history as PDF
|
124 |
+
file_name = st.sidebar.text_input("File Name to Save Chat", value="chat_history")
|
125 |
+
if st.sidebar.button("Save Chat as PDF"):
|
126 |
+
pdf_path = save_chat_history_as_pdf(st.session_state.chat_history, file_name)
|
127 |
+
with open(pdf_path, "rb") as pdf_file:
|
128 |
+
st.sidebar.download_button("Download PDF", pdf_file, file_name=f"{file_name}.pdf", mime="application/pdf")
|
129 |
+
|
130 |
+
# Display favorites
|
131 |
+
st.sidebar.write("### Favorites")
|
132 |
+
for i, (fav_query, fav_summary) in enumerate(st.session_state.favorites, 1):
|
133 |
+
st.sidebar.write(f"**{i}. {fav_query}**")
|
134 |
+
st.sidebar.write(fav_summary[:100] + "...")
|
135 |
+
|
136 |
+
if __name__ == "__main__":
|
137 |
+
main()
|
youtube.png
ADDED
![]() |
Git LFS Details
|
youtube.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from googleapiclient.discovery import build
|
4 |
+
import speech_recognition as sr
|
5 |
+
from datetime import datetime
|
6 |
+
|
7 |
+
# Set up YouTube API
|
8 |
+
API_KEY = "AIzaSyA20DXMC3HeqHs9sOMQUQ041wEkgsoFXb4" # Replace with your YouTube Data API v3 key
|
9 |
+
youtube = build('youtube', 'v3', developerKey=API_KEY)
|
10 |
+
|
11 |
+
# Function to search YouTube videos
|
12 |
+
def search_youtube(query, max_results=5):
|
13 |
+
try:
|
14 |
+
request = youtube.search().list(
|
15 |
+
q=query,
|
16 |
+
part='id,snippet',
|
17 |
+
maxResults=max_results,
|
18 |
+
type='video'
|
19 |
+
)
|
20 |
+
response = request.execute()
|
21 |
+
|
22 |
+
videos = []
|
23 |
+
for item in response['items']:
|
24 |
+
video_id = item['id']['videoId']
|
25 |
+
title = item['snippet']['title']
|
26 |
+
thumbnail = item['snippet']['thumbnails']['default']['url']
|
27 |
+
url = f'https://www.youtube.com/watch?v={video_id}'
|
28 |
+
videos.append({'title': title, 'url': url, 'video_id': video_id, 'thumbnail': thumbnail})
|
29 |
+
return videos
|
30 |
+
except Exception as e:
|
31 |
+
st.write(f"Error fetching videos: {e}")
|
32 |
+
return []
|
33 |
+
|
34 |
+
# Function for voice recognition
|
35 |
+
def voice_search():
|
36 |
+
recognizer = sr.Recognizer()
|
37 |
+
with sr.Microphone() as source:
|
38 |
+
st.write("Listening...")
|
39 |
+
audio = recognizer.listen(source)
|
40 |
+
try:
|
41 |
+
query = recognizer.recognize_google(audio)
|
42 |
+
st.success(f"You said: {query}")
|
43 |
+
return query
|
44 |
+
except sr.UnknownValueError:
|
45 |
+
st.error("Could not understand audio")
|
46 |
+
return ""
|
47 |
+
except sr.RequestError as e:
|
48 |
+
st.error(f"Could not request results from Google Speech Recognition service; {e}")
|
49 |
+
return ""
|
50 |
+
|
51 |
+
# Streamlit UI
|
52 |
+
st.title("YouTube Video Search")
|
53 |
+
st.write("Search for YouTube videos using text or voice.")
|
54 |
+
|
55 |
+
# Button for voice search
|
56 |
+
if st.button("Search by Voice"):
|
57 |
+
search_query = voice_search()
|
58 |
+
else:
|
59 |
+
# User search input
|
60 |
+
search_query = st.text_input("Enter search query", value="Python programming")
|
61 |
+
|
62 |
+
if search_query:
|
63 |
+
st.write(f"Results for '{search_query}':")
|
64 |
+
videos = search_youtube(search_query)
|
65 |
+
|
66 |
+
# Display videos one by one
|
67 |
+
for video in videos:
|
68 |
+
st.image(video['thumbnail'])
|
69 |
+
st.write(f"**Title:** {video['title']}")
|
70 |
+
st.write(f"[Watch on YouTube]({video['url']})")
|
71 |
+
|
72 |
+
# Add a button to play the video
|
73 |
+
st.video(video['url']) # This embeds the YouTube video player
|
74 |
+
|
75 |
+
st.write("---")
|
76 |
+
|
77 |
+
# Display last seen date and time
|
78 |
+
st.sidebar.write("### Last Seen")
|
79 |
+
last_seen_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
80 |
+
st.sidebar.write(f"Last seen on: {last_seen_time}")
|
81 |
+
|
82 |
+
# Footer section at the bottom of the page
|
83 |
+
st.write("---")
|
84 |
+
st.write("### Footer")
|
85 |
+
st.write("This application is built for educational purposes.")
|
86 |
+
st.write("YouTube Data API is used for video searching.")
|
87 |
+
st.write("Developed by SriKrishna")
|