Koaris commited on
Commit
7a51ee6
1 Parent(s): d76a9c5

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +52 -0
  2. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ import gradio as gr
3
+ import requests
4
+ import pandas as pd
5
+
6
+
7
+ api_key = 'AIzaSyB3o8PzB6JgCDqBdNfbyofIycOJURGyn_I'
8
+
9
+ def get_json_places(query_param,key_param):
10
+ url = f'https://maps.googleapis.com/maps/api/place/textsearch/json?query={query_param}&key={key_param}'
11
+ req = requests.get(url)
12
+ json_res = req.json()
13
+ return json_res
14
+
15
+ def get_all_results(json_file, key_param=api_key):
16
+ places_results = json_file['results']
17
+ is_next = 'next_page_token' in json_file
18
+ while is_next is True:
19
+ token = json_file['next_page_token']
20
+ url = f'https://maps.googleapis.com/maps/api/place/textsearch/json?pagetoken={token}&key={key_param}'
21
+ time.sleep(2)
22
+ new_req = requests.get(url)
23
+ json_file = new_req.json()
24
+ places_results += json_file['results']
25
+ is_next = 'next_page_token' in json_file
26
+ return places_results
27
+
28
+
29
+ def main_execution(text_search, key_param=api_key):
30
+ text_search = text_search.replace(" ", "%20")
31
+ json_obj = get_json_places(text_search,key_param)
32
+ res = get_all_results(json_obj,key_param)
33
+ data = pd.DataFrame.from_records(res)
34
+ data = data.loc[data.business_status=='OPERATIONAL', ['name','price_level', 'rating','user_ratings_total','formatted_address','types']]
35
+ data.columns = ['Όνομα καταστήματος','Επίπεδο τιμών', 'βαθμολογία','αριθμός αξιολογήσεων','διεύθυνση','τύπους']
36
+ return gr.DataFrame(data.sort_values(by='αριθμός αξιολογήσεων',ascending=False))
37
+
38
+ if __name__ == "__main__":
39
+ desc = ("## Αυτή η εφαρμογή σας βοηθά να βρείτε όλες τις καφετέριες που αναφέρονται στο google σε μια γειτονιά.")
40
+ long_desc = ("""Στο πεδίο αναζήτησης, μπορείτε να πληκτρολογήσετε το όνομα της γειτονιάς καθώς και το είδος των καταστημάτων που θέλετε να αναζητήσετε. \n
41
+ π.χ. "Φουρνοι στη Γλυφάδα, Αττική\n
42
+ Τα αποτελέσματα εμφανίζονται από τον υψηλότερο καταγεγραμμένο αριθμό αξιολογήσεων χρηστών έως τον χαμηλότερο.""")
43
+ with gr.Blocks() as demo:
44
+ gr.Markdown("# TS Platinum, εφαρμογή για κυνήγι")
45
+ gr.Markdown(desc)
46
+ gr.Markdown(long_desc)
47
+ region = gr.Textbox(label="Πεδίο αναζήτησης", info="π.χ. Φουρνοι στη Γλυφάδα, Αττική")
48
+ output_file = gr.DataFrame()
49
+ download_button = gr.Button("Βρείτε τα θηράματα!")
50
+ download_button.click(main_execution,inputs=[region], outputs=[output_file])
51
+
52
+ demo.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio==4.37.2
2
+ gradio_client==1.0.2
3
+ huggingface-hub==0.23.4
4
+ matplotlib==3.9.0
5
+ numpy==2.0.0
6
+ pandas==2.2.2
7
+ requests==2.32.3