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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pyaudio
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from sentence_transformers import SentenceTransformer
|
| 5 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
| 6 |
+
import numpy as np
|
| 7 |
+
import time
|
| 8 |
+
import speech_recognition as sr
|
| 9 |
+
from textblob import TextBlob
|
| 10 |
+
import streamlit as st
|
| 11 |
+
import seaborn as sns
|
| 12 |
+
import plotly.express as px
|
| 13 |
+
from datetime import datetime, timedelta
|
| 14 |
+
import gspread
|
| 15 |
+
from google.oauth2.service_account import Credentials
|
| 16 |
+
|
| 17 |
+
# Set up paths
|
| 18 |
+
csv_file_path = r"C:\Users\Muthuraja\OneDrive\Attachments\Desktop\second\context.csv" # Path to your CSV file
|
| 19 |
+
output_csv_path = r"C:\Users\Muthuraja\OneDrive\Attachments\Desktop\second\query_results.csv" # Path to save query results
|
| 20 |
+
|
| 21 |
+
# Google Sheets setup
|
| 22 |
+
SCOPE = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
|
| 23 |
+
CREDS_PATH = r"C:\Users\Muthuraja\Downloads\modern-cycling-444916-g6-82c207d3eb47.json" # Provide your Google credentials path
|
| 24 |
+
|
| 25 |
+
# Initialize Google Sheets connection
|
| 26 |
+
def initialize_google_sheets():
|
| 27 |
+
credentials = Credentials.from_service_account_file(CREDS_PATH, scopes=SCOPE)
|
| 28 |
+
try:
|
| 29 |
+
client = gspread.authorize(credentials)
|
| 30 |
+
sheet = client.open("SalesStores").sheet1 # Change Google Sheet name to "SalesStores"
|
| 31 |
+
return sheet
|
| 32 |
+
except gspread.exceptions.APIError as e:
|
| 33 |
+
st.error(f"Google Sheets API error: {e}")
|
| 34 |
+
return None
|
| 35 |
+
|
| 36 |
+
sheet = initialize_google_sheets()
|
| 37 |
+
|
| 38 |
+
# Function to safely load the CSV dataset
|
| 39 |
+
def load_csv_safely(file_path):
|
| 40 |
+
try:
|
| 41 |
+
# Attempt to read with error handling for bad lines
|
| 42 |
+
df = pd.read_csv(file_path, on_bad_lines='skip') # Skips malformed lines
|
| 43 |
+
# Check if the required columns exist
|
| 44 |
+
required_columns = ['question', 'product', 'price', 'features', 'ratings', 'discount']
|
| 45 |
+
for column in required_columns:
|
| 46 |
+
if column not in df.columns:
|
| 47 |
+
raise Exception(f"CSV does not contain the required column: '{column}'. Please check your CSV.")
|
| 48 |
+
|
| 49 |
+
# If 'Timestamp' column doesn't exist, create it as NaN or empty
|
| 50 |
+
if 'Timestamp' not in df.columns:
|
| 51 |
+
df['Timestamp'] = pd.NaT # Set it to NaT (Not a Time) initially
|
| 52 |
+
|
| 53 |
+
return df
|
| 54 |
+
except pd.errors.ParserError as e:
|
| 55 |
+
st.error(f"Error reading CSV file: {e}")
|
| 56 |
+
return None
|
| 57 |
+
except Exception as e:
|
| 58 |
+
st.error(f"An error occurred: {e}")
|
| 59 |
+
return None
|
| 60 |
+
|
| 61 |
+
dataset = load_csv_safely(csv_file_path) # Load the dataset safely
|
| 62 |
+
embedding_model = SentenceTransformer('all-MiniLM-L6-v2') # Pre-trained sentence transformer model
|
| 63 |
+
|
| 64 |
+
# Function to filter data by date
|
| 65 |
+
def filter_data_by_date(data, date_filter):
|
| 66 |
+
if date_filter == "Today":
|
| 67 |
+
start_date = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
| 68 |
+
data = data[data['Timestamp'] >= start_date]
|
| 69 |
+
elif date_filter == "One Week":
|
| 70 |
+
start_date = datetime.now() - timedelta(weeks=1)
|
| 71 |
+
data = data[data['Timestamp'] >= start_date]
|
| 72 |
+
return data
|
| 73 |
+
|
| 74 |
+
# Function to recognize speech using SpeechRecognition and PyAudio in chunks
|
| 75 |
+
def listen_to_speech():
|
| 76 |
+
recognizer = sr.Recognizer()
|
| 77 |
+
|
| 78 |
+
# Initialize PyAudio microphone stream
|
| 79 |
+
with sr.Microphone() as source:
|
| 80 |
+
recognizer.adjust_for_ambient_noise(source)
|
| 81 |
+
st.write("Listening...") # Optional: Add a message to indicate listening state
|
| 82 |
+
|
| 83 |
+
try:
|
| 84 |
+
# Listen for the audio input
|
| 85 |
+
audio = recognizer.listen(source, timeout=5, phrase_time_limit=10) # Listen for up to 10 seconds
|
| 86 |
+
st.write("Recognizing...") # Optional: Add a message for recognition process
|
| 87 |
+
|
| 88 |
+
# Use Google's speech recognition to convert audio to text
|
| 89 |
+
text = recognizer.recognize_google(audio)
|
| 90 |
+
st.write(f"Recognized: {text}")
|
| 91 |
+
return text # Return the text detected from the audio
|
| 92 |
+
except sr.UnknownValueError:
|
| 93 |
+
st.error("Sorry, I could not understand the audio.") # Handle case when the audio is unclear
|
| 94 |
+
return None
|
| 95 |
+
except sr.RequestError:
|
| 96 |
+
st.error("Could not request results from Google Speech Recognition service.") # Handle network issues
|
| 97 |
+
return None
|
| 98 |
+
except Exception as e:
|
| 99 |
+
st.error(f"An error occurred: {e}")
|
| 100 |
+
return None
|
| 101 |
+
|
| 102 |
+
# Function to check if the text is a greeting
|
| 103 |
+
def is_greeting(text):
|
| 104 |
+
greetings = ["hello", "hi", "hey", "good morning", "good afternoon", "good evening", "hola"]
|
| 105 |
+
return any(greeting in text.lower() for greeting in greetings)
|
| 106 |
+
|
| 107 |
+
# Function to respond to greetings
|
| 108 |
+
def respond_to_greeting():
|
| 109 |
+
st.write("Hi there! How can I assist you today? 😊")
|
| 110 |
+
|
| 111 |
+
# Function to extract the product name from the query
|
| 112 |
+
def extract_product_name(query):
|
| 113 |
+
# Ensure that all product names are strings and handle NaN values
|
| 114 |
+
for product in dataset['product'].fillna('Unknown').astype(str):
|
| 115 |
+
if product.lower() in query.lower():
|
| 116 |
+
return product
|
| 117 |
+
return None
|
| 118 |
+
|
| 119 |
+
# Function to find the best matching answer using embeddings (Retrieve part of RAG)
|
| 120 |
+
def find_answer(query):
|
| 121 |
+
if dataset is None:
|
| 122 |
+
return "Dataset not loaded properly."
|
| 123 |
+
|
| 124 |
+
# Compute the embedding of the query
|
| 125 |
+
query_embedding = embedding_model.encode([query])
|
| 126 |
+
|
| 127 |
+
# Compute embeddings for all the dataset questions
|
| 128 |
+
dataset_embeddings = embedding_model.encode(dataset['question'].tolist())
|
| 129 |
+
|
| 130 |
+
# Find the closest match using cosine similarity
|
| 131 |
+
similarities = cosine_similarity(query_embedding, dataset_embeddings)
|
| 132 |
+
|
| 133 |
+
# Get the index of the most similar question
|
| 134 |
+
closest_idx = np.argmax(similarities)
|
| 135 |
+
|
| 136 |
+
# Retrieve the product info associated with the closest question
|
| 137 |
+
closest_question = dataset.iloc[closest_idx]
|
| 138 |
+
product_name = closest_question['product']
|
| 139 |
+
price = closest_question['price']
|
| 140 |
+
features = closest_question['features']
|
| 141 |
+
ratings = closest_question['ratings']
|
| 142 |
+
discount = closest_question['discount']
|
| 143 |
+
|
| 144 |
+
# Ensure 'Timestamp' column exists before appending
|
| 145 |
+
if 'Timestamp' not in closest_question.index:
|
| 146 |
+
closest_question['Timestamp'] = datetime.now()
|
| 147 |
+
|
| 148 |
+
# Append the query and answer to the CSV file
|
| 149 |
+
new_entry = {
|
| 150 |
+
'question': query,
|
| 151 |
+
'product': product_name,
|
| 152 |
+
'price': price,
|
| 153 |
+
'features': features,
|
| 154 |
+
'ratings': ratings,
|
| 155 |
+
'discount': discount,
|
| 156 |
+
'Timestamp': datetime.now()
|
| 157 |
+
}
|
| 158 |
+
new_entry_df = pd.DataFrame([new_entry])
|
| 159 |
+
|
| 160 |
+
# Save the new entry to the CSV file
|
| 161 |
+
new_entry_df.to_csv(output_csv_path, mode='a', header=not os.path.exists(output_csv_path), index=False)
|
| 162 |
+
|
| 163 |
+
# Return specific info based on query
|
| 164 |
+
if "price" in query.lower():
|
| 165 |
+
return f"The price of {product_name} is {price}"
|
| 166 |
+
elif "features" in query.lower():
|
| 167 |
+
return f"Features of {product_name}: {features}"
|
| 168 |
+
elif "discount" in query.lower():
|
| 169 |
+
return f"The discount on {product_name} is {discount}%"
|
| 170 |
+
else:
|
| 171 |
+
return f"Product: {product_name}\nPrice: {price}\nFeatures: {features}\nRatings: {ratings}\nDiscount: {discount}%"
|
| 172 |
+
|
| 173 |
+
# Function for sentiment analysis using TextBlob with emojis
|
| 174 |
+
def analyze_sentiment_with_emoji(text):
|
| 175 |
+
# Create a TextBlob object
|
| 176 |
+
blob = TextBlob(text)
|
| 177 |
+
|
| 178 |
+
# Get the sentiment polarity (-1 to 1)
|
| 179 |
+
sentiment_score = blob.sentiment.polarity
|
| 180 |
+
|
| 181 |
+
# Determine sentiment and corresponding emoji based on the polarity score
|
| 182 |
+
if sentiment_score > 0:
|
| 183 |
+
sentiment = "Positive"
|
| 184 |
+
emoji = "😊" # Happy emoji for positive sentiment
|
| 185 |
+
elif sentiment_score < 0:
|
| 186 |
+
sentiment = "Negative"
|
| 187 |
+
emoji = "😞" # Sad emoji for negative sentiment
|
| 188 |
+
else:
|
| 189 |
+
sentiment = "Neutral"
|
| 190 |
+
emoji = "😐" # Neutral emoji for neutral sentiment
|
| 191 |
+
|
| 192 |
+
return sentiment, sentiment_score, emoji
|
| 193 |
+
|
| 194 |
+
# Function to provide product recommendations (only product names) based on the query
|
| 195 |
+
def recommend_products(query):
|
| 196 |
+
if dataset is None:
|
| 197 |
+
return "Dataset not loaded properly."
|
| 198 |
+
|
| 199 |
+
# Ensure all product names are strings and handle missing data
|
| 200 |
+
dataset['product'] = dataset['product'].fillna('Unknown').astype(str)
|
| 201 |
+
|
| 202 |
+
# Compute the embedding of the query
|
| 203 |
+
query_embedding = embedding_model.encode([query])
|
| 204 |
+
|
| 205 |
+
# Compute embeddings for all the dataset product names
|
| 206 |
+
dataset_embeddings = embedding_model.encode(dataset['product'].tolist())
|
| 207 |
+
|
| 208 |
+
# Find the closest match using cosine similarity
|
| 209 |
+
similarities = cosine_similarity(query_embedding, dataset_embeddings)
|
| 210 |
+
|
| 211 |
+
# Get the indices of the top 3 recommendations
|
| 212 |
+
top_indices = np.argsort(similarities[0])[-3:][::-1] # Get top 3 recommendations
|
| 213 |
+
|
| 214 |
+
# Return at least 3 recommendations
|
| 215 |
+
recommendations = []
|
| 216 |
+
for idx in top_indices:
|
| 217 |
+
product = dataset.iloc[idx]
|
| 218 |
+
recommendations.append({
|
| 219 |
+
'product': product['product'],
|
| 220 |
+
'price': product['price'],
|
| 221 |
+
'features': product['features'],
|
| 222 |
+
'ratings': product['ratings'],
|
| 223 |
+
'discount': product['discount']
|
| 224 |
+
}) # Append product details
|
| 225 |
+
|
| 226 |
+
# If there are less than 3 recommendations, pad with default responses
|
| 227 |
+
while len(recommendations) < 3:
|
| 228 |
+
recommendations.append({
|
| 229 |
+
'product': 'No recommendation available',
|
| 230 |
+
'price': 'N/A',
|
| 231 |
+
'features': 'N/A',
|
| 232 |
+
'ratings': 'N/A',
|
| 233 |
+
'discount': 'N/A'
|
| 234 |
+
})
|
| 235 |
+
|
| 236 |
+
return recommendations
|
| 237 |
+
|
| 238 |
+
# Function to handle the entire continuous interaction loop
|
| 239 |
+
def continuous_interaction():
|
| 240 |
+
st.title("Speech Recognition with Product Queries")
|
| 241 |
+
if st.button("Start Speech Recognition"):
|
| 242 |
+
while True: # Loop for continuous listening
|
| 243 |
+
user_input = listen_to_speech()
|
| 244 |
+
if user_input:
|
| 245 |
+
# Check if the user is greeting
|
| 246 |
+
if is_greeting(user_input):
|
| 247 |
+
respond_to_greeting()
|
| 248 |
+
continue # Skip the rest of the code and just greet
|
| 249 |
+
# Extract product name if mentioned
|
| 250 |
+
product_name = extract_product_name(user_input)
|
| 251 |
+
if product_name:
|
| 252 |
+
# If the user asks for a product like "iPhone price", respond with product details
|
| 253 |
+
st.write(f"Let me check the details for {product_name}:")
|
| 254 |
+
product_details = dataset[dataset['product'].str.lower() == product_name.lower()]
|
| 255 |
+
if not product_details.empty:
|
| 256 |
+
product_info = product_details.iloc[0]
|
| 257 |
+
st.write(f"Product: {product_info['product']}")
|
| 258 |
+
st.write(f"Price: {product_info['price']}")
|
| 259 |
+
st.write(f"Features: {product_info['features']}")
|
| 260 |
+
st.write(f"Ratings: {product_info['ratings']}")
|
| 261 |
+
st.write(f"Discount: {product_info['discount']}%")
|
| 262 |
+
else:
|
| 263 |
+
st.write("Sorry, I couldn't find the product you're asking for.")
|
| 264 |
+
else:
|
| 265 |
+
# If no specific product is mentioned, perform normal question answering
|
| 266 |
+
answer = find_answer(user_input)
|
| 267 |
+
st.write(f"Answer: {answer}")
|
| 268 |
+
|
| 269 |
+
# Sentiment Analysis with Emoji
|
| 270 |
+
sentiment, sentiment_score, emoji = analyze_sentiment_with_emoji(user_input)
|
| 271 |
+
st.write(f"Sentiment: {sentiment} (Score: {sentiment_score}) {emoji}")
|
| 272 |
+
|
| 273 |
+
# Product Recommendations based on query
|
| 274 |
+
st.write("Here are some product recommendations based on your query: ")
|
| 275 |
+
recommendations = recommend_products(user_input)
|
| 276 |
+
if recommendations:
|
| 277 |
+
for idx, rec in enumerate(recommendations, 1):
|
| 278 |
+
st.write(f"**Recommendation {idx}:**")
|
| 279 |
+
st.write(f"**Product**: {rec['product']}")
|
| 280 |
+
st.write(f"**Price**: {rec['price']}")
|
| 281 |
+
st.write(f"**Features**: {rec['features']}")
|
| 282 |
+
st.write(f"**Ratings**: {rec['ratings']}")
|
| 283 |
+
st.write(f"**Discount**: {rec['discount']}%")
|
| 284 |
+
st.write("---") # Separator between recommendations
|
| 285 |
+
|
| 286 |
+
# Handle objections if any
|
| 287 |
+
st.write("Do you like the recommendation or should I try again?")
|
| 288 |
+
if listen_to_speech(): # Listen for user feedback
|
| 289 |
+
pass
|
| 290 |
+
|
| 291 |
+
# Dashboard function
|
| 292 |
+
def display_dashboard():
|
| 293 |
+
# Here you can display your dashboard content
|
| 294 |
+
st.title("Product Dashboard")
|
| 295 |
+
st.write("Welcome to the product query dashboard!")
|
| 296 |
+
|
| 297 |
+
# Load query results from CSV
|
| 298 |
+
query_results_df = pd.read_csv(output_csv_path, on_bad_lines='skip') # Skip bad lines when loading the CSV
|
| 299 |
+
|
| 300 |
+
# Show a summary table of recent queries
|
| 301 |
+
st.subheader("Recent Queries Summary")
|
| 302 |
+
st.write(query_results_df.tail(10)) # Show the last 10 queries
|
| 303 |
+
|
| 304 |
+
# Sentiment Analysis - Pie Chart for Positive, Negative, Neutral sentiment distribution
|
| 305 |
+
sentiment_counts = query_results_df['question'].apply(lambda x: analyze_sentiment_with_emoji(x)[0]).value_counts()
|
| 306 |
+
st.subheader("Sentiment Analysis Distribution")
|
| 307 |
+
st.write(sentiment_counts)
|
| 308 |
+
|
| 309 |
+
# Pie chart for sentiment distribution
|
| 310 |
+
sentiment_fig = px.pie(
|
| 311 |
+
sentiment_counts,
|
| 312 |
+
names=sentiment_counts.index,
|
| 313 |
+
values=sentiment_counts.values,
|
| 314 |
+
title="Sentiment Distribution of Queries"
|
| 315 |
+
)
|
| 316 |
+
st.plotly_chart(sentiment_fig)
|
| 317 |
+
|
| 318 |
+
# Line Chart - Sentiment score over time (based on Timestamp)
|
| 319 |
+
query_results_df['Timestamp'] = pd.to_datetime(query_results_df['Timestamp'], errors='coerce')
|
| 320 |
+
query_results_df['sentiment_score'] = query_results_df['question'].apply(lambda x: analyze_sentiment_with_emoji(x)[1])
|
| 321 |
+
|
| 322 |
+
sentiment_time_fig = px.line(
|
| 323 |
+
query_results_df,
|
| 324 |
+
x='Timestamp',
|
| 325 |
+
y='sentiment_score',
|
| 326 |
+
title="Sentiment Score Over Time"
|
| 327 |
+
)
|
| 328 |
+
st.plotly_chart(sentiment_time_fig)
|
| 329 |
+
|
| 330 |
+
# Product-based Analysis - Product popularity (based on number of queries)
|
| 331 |
+
product_counts = query_results_df['product'].value_counts()
|
| 332 |
+
st.subheader("Product Popularity")
|
| 333 |
+
st.write(product_counts)
|
| 334 |
+
|
| 335 |
+
# Pie chart for product popularity
|
| 336 |
+
product_popularity_fig = px.pie(
|
| 337 |
+
product_counts,
|
| 338 |
+
names=product_counts.index,
|
| 339 |
+
values=product_counts.values,
|
| 340 |
+
title="Product Popularity"
|
| 341 |
+
)
|
| 342 |
+
st.plotly_chart(product_popularity_fig)
|
| 343 |
+
|
| 344 |
+
# Main code logic for running the application
|
| 345 |
+
if __name__ == "__main__":
|
| 346 |
+
choice = st.sidebar.selectbox("Select Mode", ["Dashboard", "Speech Recognition"])
|
| 347 |
+
|
| 348 |
+
if choice == "Dashboard":
|
| 349 |
+
display_dashboard() # Display dashboard if selected
|
| 350 |
+
else:
|
| 351 |
+
continuous_interaction() # Speech recognition interaction
|
context.csv
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
question,product,price,features,ratings,discount,Timestamp,
|
| 2 |
+
What is the price of iPhone 13?,iPhone 13,$799,"6.1-inch display, A15 Bionic chip, 12MP camera",4.7,10%,25-01-2025 10:30,
|
| 3 |
+
What are the features of Samsung Galaxy S22?,Samsung Galaxy S22,$999,"6.1-inch Dynamic AMOLED display, Snapdragon 8 Gen 1, 50MP camera",4.8,15%,25-01-2025 11:15,
|
| 4 |
+
Does iPhone 13 have a discount?,iPhone 13,$799,"6.1-inch display, A15 Bionic chip, 12MP camera",4.7,10%,26-01-2025 09:45,
|
| 5 |
+
Tell me about the Samsung Galaxy Watch 5,Samsung Galaxy Watch 5,$279,"1.4-inch AMOLED display, heart rate monitor, GPS",4.5,20%,26-01-2025 12:00,
|
| 6 |
+
"""Tell me about the smartphone""","""Smartphone X""",$499,"""5G, 128GB storage""",4.5,15,,
|
| 7 |
+
"""What are the best phones?""","""iPhone 13""",999,"""5G, 256GB storage""",4.8,10,,
|
| 8 |
+
"""What are the best laptops?""","""MacBook Pro""",$1999,"""16GB RAM, M1 chip""",4.9,5,,
|
| 9 |
+
What is the best sunscreen for summer?,Sunscreen,15.99,"SPF 50, Waterproof, Long-lasting",4.5,10,,
|
| 10 |
+
Can you recommend a winter jacket?,Winter Jacket,120.5,"Water-resistant, Insulated, Windproof",4.7,15,,
|
| 11 |
+
What are the top beach accessories for summer?,Beach Towel,25.99,"Quick-drying, Lightweight, Soft",4.6,20,,
|
| 12 |
+
What is the best winter boots for cold weather?,Winter Boots,79.99,"Thermal insulation, Waterproof, Non-slip sole",4.8,25,,
|
| 13 |
+
Do you have any summer dresses?,Summer Dress,49.99,"Breathable fabric, Stylish, Various sizes",4.3,10,,
|
| 14 |
+
Which heater is best for winter?,Electric Heater,89.99,"Compact, Energy-efficient, Adjustable settings",4.4,15,,
|
| 15 |
+
Can you suggest a good pair of sunglasses for summer?,Sunglasses,19.99,"UV Protection, Stylish design, Polarized",4.7,5,,
|
| 16 |
+
Do you sell winter gloves?,Winter Gloves,18.5,"Thermal lining, Waterproof, Adjustable fit",4.6,20,,
|
| 17 |
+
What is the best cooler for a summer picnic?,Cooler Box,35.99,"Insulated, Easy to carry, Durable",4.4,10,,
|
| 18 |
+
Can you recommend a heated blanket for winter?,Heated Blanket,59.99,"Multiple heat settings, Soft fabric, Machine washable",4.8,30,,
|
| 19 |
+
What is the best sunscreen for summer?,Sunscreen,15.99,"SPF 50, Waterproof, Long-lasting",4.5,10,,
|
| 20 |
+
Can you recommend a winter jacket?,Winter Jacket,120.5,"Water-resistant, Insulated, Windproof",4.7,15,,
|
| 21 |
+
What are the top beach accessories for summer?,Beach Towel,25.99,"Quick-drying, Lightweight, Soft",4.6,20,,
|
| 22 |
+
What is the best winter boots for cold weather?,Winter Boots,79.99,"Thermal insulation, Waterproof, Non-slip sole",4.8,25,,
|
| 23 |
+
Do you have any summer dresses for girls?,Girls' Summer Dress (Floral),39.99,"Breathable fabric, Stylish, Various sizes",4.3,15,,
|
| 24 |
+
What is the best summer dress for boys?,Boys' Summer T-shirt,19.99,"Comfortable, Soft fabric, Various colors",4.5,10,,Rating
|
| 25 |
+
Which heater is best for winter?,Electric Heater,89.99,"Compact, Energy-efficient, Adjustable settings",4.4,15,,4.6
|
| 26 |
+
Can you suggest a good pair of sunglasses for summer?,Sunglasses,19.99,"UV Protection, Stylish design, Polarized",4.7,5,$800,4.7
|
| 27 |
+
Do you sell winter gloves?,Winter Gloves,18.5,"Thermal lining, Waterproof, Adjustable fit",4.6,20,$150,4.8
|
| 28 |
+
What is the best cooler for a summer picnic?,Cooler Box,35.99,"Insulated, Easy to carry, Durable",4.4,10,Price,Rating
|
| 29 |
+
Can you recommend a heated blanket for winter?,Heated Blanket,59.99,"Multiple heat settings, Soft fabric, Machine washable",4.8,30,$1200,4.9
|
| 30 |
+
Can you recommend a good pair of AirPods?,AirPods Pro,249.99,"Active Noise Cancellation, Wireless, Sweat-resistant",4.8,15,,5
|
| 31 |
+
What is the best sports bike for city commuting?,Sports Bike,499.99,"Lightweight, Fast, Ergonomic design",4.6,20,Laptop,5.1
|
| 32 |
+
Which electric car is best for long trips?,Electric Car (Tesla),39999.99,"Autopilot, Long-range, Fast charging",4.9,10,,
|
| 33 |
+
What is the best electric bike for urban areas?,Electric Bike,799.99,"Powerful motor, Long battery life, Comfortable",4.7,25,,
|
| 34 |
+
Can you recommend a family SUV for winter driving?,Family SUV (Toyota),32000,"All-wheel drive, Spacious, Heated seats",4.5,5,,
|
| 35 |
+
"• Price: $699.99",,,,,,,
|
| 36 |
+
8. Apple iPad Air (4th Gen),iPhone 13,799,"128GB Storage, A15 Bionic Chip, 5G Support, 12MP Camera",4.8,10,,
|
| 37 |
+
"• Brand: Apple",Samsung Galaxy S21,749,"128GB Storage, Exynos 2100 Chipset, 5G Support, 64MP Camera",4.7,15,,
|
| 38 |
+
"• Published Year: 2020",OnePlus 9,699,"128GB Storage, Snapdragon 888 Chipset, 5G Support, 48MP Camera",4.5,12,,
|
| 39 |
+
"• Key Features: A14 Bionic chip",Google Pixel 6,599,"128GB Storage, Google Tensor Chip, 5G Support, 50MP Camera",4.6,8,,
|
| 40 |
+
"• Price: $599",Xiaomi Mi 11,599,"128GB Storage, Snapdragon 888, 5G Support, 108MP Camera",4.4,18,,
|
| 41 |
+
9. NVIDIA GeForce RTX 3080 Graphics Card,Samsung Galaxy A52,349,"128GB Storage, Snapdragon 720G Chipset, 5G Support, 64MP Camera",4.2,5,,
|
| 42 |
+
"• Brand: NVIDIA",Realme 8 Pro,279,"128GB Storage, Snapdragon 720G, 4G Support, 108MP Camera",4.3,10,,
|
| 43 |
+
"• Published Year: 2020",Motorola Moto G Power,199,"64GB Storage, Snapdragon 662, 4G Support, 48MP Camera",4,20,,
|
| 44 |
+
"• Key Features: 10GB GDDR6X memory", Ray tracing technology, 4K gaming, Real-time AI-powered graphics,,,,
|
| 45 |
+
"• Price: $699 (varies by model)",Asus laptop,,,,,,
|
| 46 |
+
10. Sony PlayStation 5 (PS5),,,,,,,
|
| 47 |
+
"• Brand: Sony",,,,,,,
|
| 48 |
+
"• Published Year: 2020",,,,,,,
|
| 49 |
+
"• Key Features: Custom SSD for fast load times", Ray tracing support, 4K gaming at 120Hz, DualSense wireless controller with haptic feedback,,,,
|
| 50 |
+
"• Price: $499 (Standard Edition)",,,,,,,
|
| 51 |
+
What is the price of iPhone 13?,iPhone 13,$799,"6.1-inch display, A15 Bionic chip, 12MP camera",4.7,10%,25-01-2025 10:30,
|
| 52 |
+
What are the features of Samsung Galaxy S22?,Samsung Galaxy S22,$999,"6.1-inch Dynamic AMOLED display, Snapdragon 8 Gen 1, 50MP camera",4.8,15%,25-01-2025 11:15,
|
| 53 |
+
Does iPhone 13 have a discount?,iPhone 13,$799,"6.1-inch display, A15 Bionic chip, 12MP camera",4.7,10%,26-01-2025 09:45,
|
| 54 |
+
Tell me about the Samsung Galaxy Watch 5,Samsung Galaxy Watch 5,$279,"1.4-inch AMOLED display, heart rate monitor, GPS",4.5,20%,26-01-2025 12:00,
|
modern-cycling-444916-g6-82c207d3eb47.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"type": "service_account",
|
| 3 |
+
"project_id": "modern-cycling-444916-g6",
|
| 4 |
+
"private_key_id": "82c207d3eb4740dba64878f4b688878d8896e8a4",
|
| 5 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCW7JkEdI5swNhs\nu6ojAP0ocVTd5ScpyB7/z+04iVOnzBQYveM54hKgktS1G6vwseQcygmSJaoXr4tr\nAwZzdF6FMH+WcoRlMLerZqH4QZY6PngtPm83xd7l+nvDHRKXOfCYe5UymHRyYWI1\nJssAnZ+VaIx9G81NqvZLC1XgV2SDMbK+Y2g3CS0UC0XnROj1S7qm3Yw09RcQLbLf\nNL9k36qhtMpOchXkjgHbGzAY/JhGDQr68zTgWgMG72sEGmDOeSkyJQ6ifevKPGDT\nF9/zX1IrX9edyujd7l2UuL2Z3eBd4EY3lb+yvGWzzXV0fwhIWZy3abygaKFvy+1L\nMnzugr3PAgMBAAECggEANYHugjDcqdv5Hxutpzlbh7Ied4kdyGdl7iYGoYu2eAAX\ng+oWnFf1aK6F8Su9WtmG2Vob6I+n7TvUfv0UlWxFco0OPwWcwM9z3rXFaOG/5Chv\nrQK8pZZ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+bqxyN+QFEmWhDcXPx+hIENIYu770RZx1XJlBAoDx8\nssEmKmJ96Nj5ISqOS1SrPdY=\n-----END PRIVATE KEY-----\n",
|
| 6 |
+
"client_email": "sales-54@modern-cycling-444916-g6.iam.gserviceaccount.com",
|
| 7 |
+
"client_id": "116249367824185236800",
|
| 8 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 9 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 10 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 11 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/sales-54%40modern-cycling-444916-g6.iam.gserviceaccount.com",
|
| 12 |
+
"universe_domain": "googleapis.com"
|
| 13 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
PyPDF2
|
| 2 |
+
streamlit
|
| 3 |
+
transformers
|
| 4 |
+
gspread
|
| 5 |
+
google-auth
|
| 6 |
+
pandas
|
| 7 |
+
matplotlib
|
| 8 |
+
reportlab
|
| 9 |
+
SpeechRecognition
|
| 10 |
+
google-auth-oauthlib
|
| 11 |
+
google-auth-httplib2
|
| 12 |
+
plotly
|
| 13 |
+
torch
|
| 14 |
+
datasets
|
| 15 |
+
vaderSentiment
|
| 16 |
+
seaborn
|
| 17 |
+
|
| 18 |
+
|