import streamlit as st import faiss import numpy as np import pandas as pd import cohere from datetime import datetime import os from google_play_scraper import app from dotenv import load_dotenv load_dotenv() # Initialize Cohere client cohere_api_key = os.getenv('api') # Replace with your Cohere API key co = cohere.Client(cohere_api_key) # Load the FAISS index from a file index = faiss.read_index("faiss_index.bin") # Load the DataFrame csv_file_path = r'C:\Users\Dell\3D Objects\NLP\gg\nowgg_embeddings.csv' # Replace with the path to your CSV file test3 = pd.read_csv(csv_file_path) # Function to get embedding for a query using Cohere def get_query_embedding(query): response = co.embed(texts=[query]) return np.array(response.embeddings[0][:250]).astype('float32') # Function to perform similarity search def search_similar(query, k=5): query_embedding = get_query_embedding(query).reshape(1, -1) distances, indices = index.search(query_embedding, k) results = [] for idx in indices[0]: product_id = test3.iloc[idx]['product_id'] # Fetch app details from Google Play Store app_details = app(product_id) result = { 'title': test3.iloc[idx]['title'], 'product_id': test3.iloc[idx]['product_id'], 'description': test3.iloc[idx]['final_description'], 'link': test3.iloc[idx]['link'], #'icon':app_details["icon"] 'video':app_details["video"] } results.append(result) return results # Function to save feedback def save_feedback(query, feedback): feedback_data = { 'timestamp': [datetime.now().strftime("%Y-%m-%d %H:%M:%S")], 'query': [query], 'feedback': [feedback] } feedback_df = pd.DataFrame(feedback_data) feedback_df.to_csv('feedback.csv', mode='a', header=False, index=False) path=r"C:\Users\Dell\3D Objects\NLP\game.jpg" # HTML & CSS for the app st.markdown(""" """, unsafe_allow_html=True) # Streamlit app st.markdown('