Adi016 commited on
Commit
88610a0
·
verified ·
1 Parent(s): 86d2ae6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +164 -164
app.py CHANGED
@@ -1,164 +1,164 @@
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
-
11
- load_dotenv()
12
-
13
-
14
- # Initialize Cohere client
15
- cohere_api_key = os.getenv('api') # Replace with your Cohere API key
16
- co = cohere.Client(cohere_api_key)
17
-
18
- # Load the FAISS index from a file
19
- index = faiss.read_index("faiss_index.bin")
20
-
21
- # Load the DataFrame
22
- csv_file_path = r'C:\Users\Dell\3D Objects\NLP\gg\nowgg_embeddings.csv' # Replace with the path to your CSV file
23
- test3 = pd.read_csv(csv_file_path)
24
-
25
- # Function to get embedding for a query using Cohere
26
- def get_query_embedding(query):
27
- response = co.embed(texts=[query])
28
- return np.array(response.embeddings[0][:250]).astype('float32')
29
-
30
- # Function to perform similarity search
31
- def search_similar(query, k=5):
32
- query_embedding = get_query_embedding(query).reshape(1, -1)
33
- distances, indices = index.search(query_embedding, k)
34
-
35
- results = []
36
- for idx in indices[0]:
37
- product_id = test3.iloc[idx]['product_id']
38
- # Fetch app details from Google Play Store
39
- app_details = app(product_id)
40
- result = {
41
- 'title': test3.iloc[idx]['title'],
42
- 'product_id': test3.iloc[idx]['product_id'],
43
- 'description': test3.iloc[idx]['final_description'],
44
- 'link': test3.iloc[idx]['link'],
45
- #'icon':app_details["icon"]
46
- 'video':app_details["video"]
47
- }
48
- results.append(result)
49
- return results
50
-
51
- # Function to save feedback
52
- def save_feedback(query, feedback):
53
- feedback_data = {
54
- 'timestamp': [datetime.now().strftime("%Y-%m-%d %H:%M:%S")],
55
- 'query': [query],
56
- 'feedback': [feedback]
57
- }
58
- feedback_df = pd.DataFrame(feedback_data)
59
-
60
-
61
- feedback_df.to_csv('feedback.csv', mode='a', header=False, index=False)
62
-
63
-
64
- path=r"C:\Users\Dell\3D Objects\NLP\game.jpg"
65
- # HTML & CSS for the app
66
- st.markdown("""
67
- <style>
68
- body {
69
- font-family: 'Arial', sans-serif;
70
-
71
- }
72
- .title {
73
- font-size: 2.5em;
74
- color: #4CAF50;
75
- text-align: center;
76
- margin-bottom: 20px;
77
- }
78
- .query-input {
79
- text-align: center;
80
- margin-bottom: 20px;
81
- }
82
- .result-card {
83
- background-color: #f9f9f9;
84
- border-radius: 10px;
85
- padding: 20px;
86
- margin-bottom: 20px;
87
- box-shadow: 0 2px 5px rgba(0,0,0,0.1);
88
- }
89
- .result-title {
90
- font-size: 1.5em;
91
- color: #333;
92
- margin-bottom: 10px;
93
- }
94
- .result-productid {
95
- font-size: 1.0em;
96
- color: #333;
97
- margin-bottom: 5px;
98
- }
99
- .result-link {
100
- color: #0066cc;
101
- text-decoration: none;
102
- }
103
- .result-link:hover {
104
- text-decoration: underline;
105
- }
106
- .feedback-section {
107
- margin-top: 40px;
108
- text-align: center;
109
- }
110
- .feedback-textarea {
111
- width: 100%;
112
- padding: 10px;
113
- border-radius: 5px;
114
- border: 1px solid #ccc;
115
- margin-bottom: 20px;
116
- }
117
- .submit-btn {
118
- background-color: #4CAF50;
119
- color: white;
120
- padding: 10px 20px;
121
- border: none;
122
- border-radius: 5px;
123
- cursor: pointer;
124
- }
125
- .submit-btn:hover {
126
- background-color: #45a049;
127
- }
128
- </style>
129
- """, unsafe_allow_html=True)
130
-
131
- # Streamlit app
132
- st.markdown('<div class="title">Game Recommendation System</div>', unsafe_allow_html=True)
133
-
134
- query = st.text_input("Enter your query:", key="query_input", placeholder="Type something...")
135
- if query:
136
- top_k_results = search_similar(query)
137
- st.write('<div class="query-input">Top recommendations:</div>', unsafe_allow_html=True)
138
-
139
- for result in top_k_results:
140
- #img=result["product_id"]
141
- st.markdown(f"""
142
- <div class="result-card">
143
- <div class="result-title">{result['title']}</div>
144
- <div><a class="result-link" href="{result['link']}">Link</a></div>
145
- </div>
146
- """, unsafe_allow_html=True)
147
-
148
- st.video(result['video'])
149
- #video_url=result['video'] # Display the image
150
-
151
-
152
-
153
-
154
-
155
- st.markdown('<div class="feedback-section">################ Feedback #####################</div>', unsafe_allow_html=True)
156
- feedback = st.text_area("Please provide your feedback here:", key="feedback_textarea", height=100)
157
- if st.button("Submit Feedback", key="submit_feedback"):
158
- save_feedback(query, feedback)
159
- st.write("Thank you for your feedback!")
160
-
161
- # Run the app with:
162
- # streamlit run hello.py
163
- #<div class="result-description">**Description**: {result['description']}</div>
164
- #<div class="result-productid">**Product-id**{result['product_id']}</div>
 
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
+
11
+ load_dotenv()
12
+
13
+
14
+ # Initialize Cohere client
15
+ cohere_api_key = os.getenv('CO_API_KEY') # Replace with your Cohere API key
16
+ co = cohere.Client(cohere_api_key)
17
+
18
+ # Load the FAISS index from a file
19
+ index = faiss.read_index("faiss_index.bin")
20
+
21
+ # Load the DataFrame
22
+ csv_file_path = r'C:\Users\Dell\3D Objects\NLP\gg\nowgg_embeddings.csv' # Replace with the path to your CSV file
23
+ test3 = pd.read_csv(csv_file_path)
24
+
25
+ # Function to get embedding for a query using Cohere
26
+ def get_query_embedding(query):
27
+ response = co.embed(texts=[query])
28
+ return np.array(response.embeddings[0][:250]).astype('float32')
29
+
30
+ # Function to perform similarity search
31
+ def search_similar(query, k=5):
32
+ query_embedding = get_query_embedding(query).reshape(1, -1)
33
+ distances, indices = index.search(query_embedding, k)
34
+
35
+ results = []
36
+ for idx in indices[0]:
37
+ product_id = test3.iloc[idx]['product_id']
38
+ # Fetch app details from Google Play Store
39
+ app_details = app(product_id)
40
+ result = {
41
+ 'title': test3.iloc[idx]['title'],
42
+ 'product_id': test3.iloc[idx]['product_id'],
43
+ 'description': test3.iloc[idx]['final_description'],
44
+ 'link': test3.iloc[idx]['link'],
45
+ #'icon':app_details["icon"]
46
+ 'video':app_details["video"]
47
+ }
48
+ results.append(result)
49
+ return results
50
+
51
+ # Function to save feedback
52
+ def save_feedback(query, feedback):
53
+ feedback_data = {
54
+ 'timestamp': [datetime.now().strftime("%Y-%m-%d %H:%M:%S")],
55
+ 'query': [query],
56
+ 'feedback': [feedback]
57
+ }
58
+ feedback_df = pd.DataFrame(feedback_data)
59
+
60
+
61
+ feedback_df.to_csv('feedback.csv', mode='a', header=False, index=False)
62
+
63
+
64
+ path=r"C:\Users\Dell\3D Objects\NLP\game.jpg"
65
+ # HTML & CSS for the app
66
+ st.markdown("""
67
+ <style>
68
+ body {
69
+ font-family: 'Arial', sans-serif;
70
+
71
+ }
72
+ .title {
73
+ font-size: 2.5em;
74
+ color: #4CAF50;
75
+ text-align: center;
76
+ margin-bottom: 20px;
77
+ }
78
+ .query-input {
79
+ text-align: center;
80
+ margin-bottom: 20px;
81
+ }
82
+ .result-card {
83
+ background-color: #f9f9f9;
84
+ border-radius: 10px;
85
+ padding: 20px;
86
+ margin-bottom: 20px;
87
+ box-shadow: 0 2px 5px rgba(0,0,0,0.1);
88
+ }
89
+ .result-title {
90
+ font-size: 1.5em;
91
+ color: #333;
92
+ margin-bottom: 10px;
93
+ }
94
+ .result-productid {
95
+ font-size: 1.0em;
96
+ color: #333;
97
+ margin-bottom: 5px;
98
+ }
99
+ .result-link {
100
+ color: #0066cc;
101
+ text-decoration: none;
102
+ }
103
+ .result-link:hover {
104
+ text-decoration: underline;
105
+ }
106
+ .feedback-section {
107
+ margin-top: 40px;
108
+ text-align: center;
109
+ }
110
+ .feedback-textarea {
111
+ width: 100%;
112
+ padding: 10px;
113
+ border-radius: 5px;
114
+ border: 1px solid #ccc;
115
+ margin-bottom: 20px;
116
+ }
117
+ .submit-btn {
118
+ background-color: #4CAF50;
119
+ color: white;
120
+ padding: 10px 20px;
121
+ border: none;
122
+ border-radius: 5px;
123
+ cursor: pointer;
124
+ }
125
+ .submit-btn:hover {
126
+ background-color: #45a049;
127
+ }
128
+ </style>
129
+ """, unsafe_allow_html=True)
130
+
131
+ # Streamlit app
132
+ st.markdown('<div class="title">Game Recommendation System</div>', unsafe_allow_html=True)
133
+
134
+ query = st.text_input("Enter your query:", key="query_input", placeholder="Type something...")
135
+ if query:
136
+ top_k_results = search_similar(query)
137
+ st.write('<div class="query-input">Top recommendations:</div>', unsafe_allow_html=True)
138
+
139
+ for result in top_k_results:
140
+ #img=result["product_id"]
141
+ st.markdown(f"""
142
+ <div class="result-card">
143
+ <div class="result-title">{result['title']}</div>
144
+ <div><a class="result-link" href="{result['link']}">Link</a></div>
145
+ </div>
146
+ """, unsafe_allow_html=True)
147
+
148
+ st.video(result['video'])
149
+ #video_url=result['video'] # Display the image
150
+
151
+
152
+
153
+
154
+
155
+ st.markdown('<div class="feedback-section">################ Feedback #####################</div>', unsafe_allow_html=True)
156
+ feedback = st.text_area("Please provide your feedback here:", key="feedback_textarea", height=100)
157
+ if st.button("Submit Feedback", key="submit_feedback"):
158
+ save_feedback(query, feedback)
159
+ st.write("Thank you for your feedback!")
160
+
161
+ # Run the app with:
162
+ # streamlit run hello.py
163
+ #<div class="result-description">**Description**: {result['description']}</div>
164
+ #<div class="result-productid">**Product-id**{result['product_id']}</div>