Upload 7 files
Browse files- .gitignore +1 -0
- Procfile.txt +1 -0
- app.py +170 -0
- faiss_index.bin +3 -0
- firegame.json +13 -0
- nowgg_embeddings.csv +0 -0
- requirements.txt +8 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.env
|
Procfile.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
web: streamlit run app.py
|
app.py
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import faiss
|
3 |
+
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
+
import cohere
|
6 |
+
from datetime import datetime
|
7 |
+
import os
|
8 |
+
from google_play_scraper import app
|
9 |
+
from dotenv import load_dotenv
|
10 |
+
import firebase_admin
|
11 |
+
from firebase_admin import credentials, db
|
12 |
+
|
13 |
+
load_dotenv()
|
14 |
+
|
15 |
+
|
16 |
+
# Initialize Cohere client
|
17 |
+
cohere_api_key = os.getenv('CO_API_KEY') # Replace with your Cohere API key
|
18 |
+
co = cohere.Client(cohere_api_key)
|
19 |
+
|
20 |
+
# Load the FAISS index from a file
|
21 |
+
index = faiss.read_index("faiss_index.bin")
|
22 |
+
|
23 |
+
# Load the DataFrame
|
24 |
+
#csv_file_path = r'C:\Users\Dell\3D Objects\NLP\gg\nowgg_embeddings.csv' # Replace with the path to your CSV file
|
25 |
+
test3 = pd.read_csv("nowgg_embeddings.csv")
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
if not firebase_admin._apps:
|
30 |
+
cred = credentials.Certificate("firegame.json") # Replace with the path to your Firebase JSON file
|
31 |
+
firebase_admin.initialize_app(cred, {
|
32 |
+
'databaseURL': 'https://game-66133-default-rtdb.firebaseio.com/'
|
33 |
+
})
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
# Function to get embedding for a query using Cohere
|
38 |
+
def get_query_embedding(query):
|
39 |
+
response = co.embed(texts=[query])
|
40 |
+
return np.array(response.embeddings[0][:250]).astype('float32')
|
41 |
+
|
42 |
+
# Function to perform similarity search
|
43 |
+
def search_similar(query, k=5):
|
44 |
+
query_embedding = get_query_embedding(query).reshape(1, -1)
|
45 |
+
distances, indices = index.search(query_embedding, k)
|
46 |
+
|
47 |
+
results = []
|
48 |
+
for idx in indices[0]:
|
49 |
+
product_id = test3.iloc[idx]['product_id']
|
50 |
+
# Fetch app details from Google Play Store
|
51 |
+
app_details = app(product_id)
|
52 |
+
result = {
|
53 |
+
'title': test3.iloc[idx]['title'],
|
54 |
+
'product_id': test3.iloc[idx]['product_id'],
|
55 |
+
'description': test3.iloc[idx]['final_description'],
|
56 |
+
'link': test3.iloc[idx]['link'],
|
57 |
+
#'icon':app_details["icon"]
|
58 |
+
'video':app_details["video"]
|
59 |
+
}
|
60 |
+
results.append(result)
|
61 |
+
return results
|
62 |
+
|
63 |
+
# Function to save feedback
|
64 |
+
def save_feedback_to_firebase(query, feedback):
|
65 |
+
ref = db.reference('feedback')
|
66 |
+
feedback_data = {
|
67 |
+
'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
68 |
+
'query': query,
|
69 |
+
'feedback': feedback
|
70 |
+
}
|
71 |
+
ref.push(feedback_data)
|
72 |
+
|
73 |
+
|
74 |
+
#path=r"C:\Users\Dell\3D Objects\NLP\game.jpg"
|
75 |
+
# HTML & CSS for the app
|
76 |
+
st.markdown("""
|
77 |
+
<style>
|
78 |
+
body {
|
79 |
+
font-family: 'Arial', sans-serif;
|
80 |
+
|
81 |
+
}
|
82 |
+
.title {
|
83 |
+
font-size: 2.5em;
|
84 |
+
color: #4CAF50;
|
85 |
+
text-align: center;
|
86 |
+
margin-bottom: 20px;
|
87 |
+
}
|
88 |
+
.query-input {
|
89 |
+
text-align: center;
|
90 |
+
margin-bottom: 20px;
|
91 |
+
}
|
92 |
+
.result-card {
|
93 |
+
background-color: #f9f9f9;
|
94 |
+
border-radius: 10px;
|
95 |
+
padding: 20px;
|
96 |
+
margin-bottom: 20px;
|
97 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
98 |
+
}
|
99 |
+
.result-title {
|
100 |
+
font-size: 1.5em;
|
101 |
+
color: #333;
|
102 |
+
margin-bottom: 10px;
|
103 |
+
}
|
104 |
+
.result-productid {
|
105 |
+
font-size: 1.0em;
|
106 |
+
color: #333;
|
107 |
+
margin-bottom: 5px;
|
108 |
+
}
|
109 |
+
.result-link {
|
110 |
+
color: #0066cc;
|
111 |
+
text-decoration: none;
|
112 |
+
}
|
113 |
+
.result-link:hover {
|
114 |
+
text-decoration: underline;
|
115 |
+
}
|
116 |
+
.feedback-section {
|
117 |
+
margin-top: 40px;
|
118 |
+
text-align: center;
|
119 |
+
}
|
120 |
+
.feedback-textarea {
|
121 |
+
width: 100%;
|
122 |
+
padding: 10px;
|
123 |
+
border-radius: 5px;
|
124 |
+
border: 1px solid #ccc;
|
125 |
+
margin-bottom: 20px;
|
126 |
+
}
|
127 |
+
.submit-btn {
|
128 |
+
background-color: #4CAF50;
|
129 |
+
color: white;
|
130 |
+
padding: 10px 20px;
|
131 |
+
border: none;
|
132 |
+
border-radius: 5px;
|
133 |
+
cursor: pointer;
|
134 |
+
}
|
135 |
+
.submit-btn:hover {
|
136 |
+
background-color: #45a049;
|
137 |
+
}
|
138 |
+
</style>
|
139 |
+
""", unsafe_allow_html=True)
|
140 |
+
|
141 |
+
# Streamlit app
|
142 |
+
st.markdown('<div class="title">Game Recommendation System</div>', unsafe_allow_html=True)
|
143 |
+
|
144 |
+
query = st.text_input("Enter your query:", key="query_input", placeholder="Type something...")
|
145 |
+
if query:
|
146 |
+
top_k_results = search_similar(query)
|
147 |
+
st.write('<div class="query-input">Top recommendations:</div>', unsafe_allow_html=True)
|
148 |
+
|
149 |
+
for result in top_k_results:
|
150 |
+
#img=result["product_id"]
|
151 |
+
st.markdown(f"""
|
152 |
+
<div class="result-card">
|
153 |
+
<div class="result-title">{result['title']}</div>
|
154 |
+
<div><a class="result-link" href="{result['link']}">Link</a></div>
|
155 |
+
</div>
|
156 |
+
""", unsafe_allow_html=True)
|
157 |
+
|
158 |
+
st.video(result['video'])
|
159 |
+
#video_url=result['video'] # Display the image
|
160 |
+
|
161 |
+
|
162 |
+
|
163 |
+
|
164 |
+
|
165 |
+
st.markdown('<div class="feedback-section">################ Feedback #####################</div>', unsafe_allow_html=True)
|
166 |
+
feedback = st.text_area("Please provide your feedback here:", key="feedback_textarea", height=100)
|
167 |
+
if st.button("Submit Feedback", key="submit_feedback"):
|
168 |
+
save_feedback_to_firebase(query, feedback)
|
169 |
+
st.write("Thank you for your feedback!")
|
170 |
+
|
faiss_index.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:31fb60f8cbca9defa4543be3f7a46882d8ac22f76f980b75b45db69d9d235fc7
|
3 |
+
size 304045
|
firegame.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"type": "service_account",
|
3 |
+
"project_id": "game-66133",
|
4 |
+
"private_key_id": "cb4b8d26921f9f3923e5a61f9dc255f9ea5d7187",
|
5 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCNJTU/Hhw70QZj\nXk1DJXW6X37euoAnjgXYF/4mD5Q4t8y0GYhrCmCTR0cBGdDBSw2Rjq96Mxg5FDNY\ne8ExXRA9+sG7035MYwW62CUoW6JdDPPflSHX9KNrOSublhZFpD5Pr+Rq6ZcelMBq\njlqGiN2JagXIEvYg5xFtbRjVVY60UwjNuWtYPbgsCsS1LSvyfa5Q7y0rnOu17+o9\n+6jiZZqpUfMVWPQyWt0JqSHWC0CKhuACS/SkwtSiQR8BVGmcZ8KRyNwFtExsm8Xi\njFtzTAAIWrnd2G9SZP2S7Y/lA2310FnoHVXdmbPYtRIfPlWQFWD4Ydw8T5YerSJN\nTsS881mdAgMBAAECggEABPxyAkNNiwgUz4YsI47wtunwYOzktxZWJYP0zKJoluJY\nqb9sfso0jtoJ65jeXjMJDSx7DXg9nFKW3RguGHt++zmJsNlv+5cp7iem6biRpp4y\nWqJ5j21LJ/AH7Cyj/RzSvgeVgaNeh8wzH0XdHns6Ru7xuld/zg9roa/PcfCI+dzB\nn9jQslAW/+8xSm4YLb2QnCONcE3pSyTMfoCqwXcJFPuVqK0GfdJRmmztqhZRxrK7\nhTK66v99nd+CzZi6GTE2+0aVjF0nTfaQ2Z4wJS+Rv5B7v9Z+igW42sdtRYJ9PxkO\n6ymG5LA96SbkU8CP6g49s8znhmfc5BYBsA5xQmaPkQKBgQDHGfzUTjgPcSYkrDyl\nbp5tzq1LD9law1673vHueM6RoQL83jsepXolbIjHW6xLskSsS5CKTIrgXVNFwxuA\nfjyZBk8WLEtbk1HMY/f1FSv/sP53GNcoPa27EKZHYxWkyoeQr8P3Bmbc2z9gXcu9\ng/SX2YOyJWgJxOhHIzpx/gePqQKBgQC1eziTq75XJC0egD6UWvNkqa2JvON5iU7I\nrrVBzBSNJjzLGVn39MQIAwSW0EC19l722Y3TwLjj/i8IGLvm+Hb19mm9j9YwXIAy\nDUEbjx95Y0uaXWfsaEzc+3l/ST+oJxqjMdmApx7L2icdVFJ4y/7nFPWk4sMi3hoZ\nBjOnoS2C1QKBgQClB8NrbtJE6nLFXwZ90Wz8c51sZFyzQNFbQ/agxf3i8+T4GHRE\neMEAGDBfnnr323HUpmXOXJeYVYLahlhbb0dnR7VyGZD0/O2GTy6ONNhdfiXOLgbZ\nUhaYwbox3c1o5H7tzOLP9Lx6QDkN9XEVSzUIUME6for33gDyRh8BsaAu0QKBgG5h\nfP7sZb/ww/SaQfXP/9wJDAELvzur1RxgjuRvMUzMpgtN5xfWaukIlOD513IVYJs5\npXbW8F3Tu11sVdVc6FYfwx7F/pu5l0taHnCZs6YMS+6ew1fZ9G4wEizmK26mIiCC\ncG08uJF6pXHEWMkaIncAm4vnVJK/jhYMXJynftvlAoGARlMCCuglkuTfkK0y9rL5\nmCD/E8t0wMJ8nxViW6985MzRhPEy8MgieA6zQ/qAs/NzcJGyAdzKiKYuVruOP10l\n0uYOE8ZsA/P5USkE9FLpPqWdLEtX/WRQNIjguVcFJ3zl7uToRD6/a/bNafXFdR2R\n6QoUZmEZzlFkpB7QWKGJ73k=\n-----END PRIVATE KEY-----\n",
|
6 |
+
"client_email": "[email protected]",
|
7 |
+
"client_id": "103226603315659330422",
|
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/firebase-adminsdk-jtqbp%40game-66133.iam.gserviceaccount.com",
|
12 |
+
"universe_domain": "googleapis.com"
|
13 |
+
}
|
nowgg_embeddings.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pip==24.1
|
2 |
+
numpy==1.24.3
|
3 |
+
pandas==1.4.2
|
4 |
+
faiss-cpu==1.7.4
|
5 |
+
cohere==5.5.8
|
6 |
+
google_play_scraper
|
7 |
+
python-dotenv
|
8 |
+
firebase-admin==6.5.0
|