hra commited on
Commit
029b270
·
1 Parent(s): b99eb74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -1
app.py CHANGED
@@ -19,11 +19,29 @@ import matplotlib
19
  import datetime
20
  from datetime import datetime, date, time, timedelta
21
  import os
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  with open('lastradartext.txt', 'r') as file:
24
  data_old = file.read()
25
  value1,value2,value3,value4,value5,value6=data_old.split('SEPERATOR')
26
 
 
 
 
 
 
 
 
27
  def getstuff(openapikey):
28
  dateforfilesave=datetime.today().strftime("%d-%m-%Y %I:%M%p")
29
  print(dateforfilesave)
@@ -145,13 +163,34 @@ def getstuff(openapikey):
145
  clusterstextlist.append("Cluster "+str(i)+"\nTheme:"+response["choices"][0]["text"].replace("\n", "")+'\n'+reviews+'\n'+"-" * 10+'\n\n')
146
 
147
  textlist=[mainlistofanswers[0],"SEPERATOR",mainlistofanswers[1],"SEPERATOR",mainlistofanswers[2],"SEPERATOR",mainlistofanswers[3],"SEPERATOR",desc_tmp,"SEPERATOR","".join(clusterstextlist)]
 
148
  with open('lastradartext.txt', 'w') as f:
149
  for line in textlist:
150
  f.write(f"{line}\n")
151
- print('Came here 8')
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  with open('lastradartext.txt', 'r') as file:
153
  data_old = file.read()
154
  value1,value2,value3,value4,value5,value6=data_old.split('SEPERATOR')
 
 
 
 
 
 
 
155
  return 'lasttechradar.png',mainlistofanswers[0],mainlistofanswers[1],mainlistofanswers[2],mainlistofanswers[3],desc_tmp,"".join(clusterstextlist)
156
 
157
  with gr.Blocks() as demo:
 
19
  import datetime
20
  from datetime import datetime, date, time, timedelta
21
  import os
22
+ from werkzeug.utils import secure_filename
23
+ from google.cloud import storage
24
+
25
+ ###download both text and image from cloud to display
26
+ bucket_name = "trends_chrome_extension_bucket"
27
+ source_blob_name = 'lastradartext.txt'
28
+ destination_file_name= 'lastradartext.txt'
29
+ storage_client = storage.Client()
30
+ bucket = storage_client.bucket(bucket_name)
31
+ blob = bucket.blob(source_blob_name)
32
+ blob.download_to_filename(destination_file_name)
33
 
34
  with open('lastradartext.txt', 'r') as file:
35
  data_old = file.read()
36
  value1,value2,value3,value4,value5,value6=data_old.split('SEPERATOR')
37
 
38
+ source_blob_name = 'lasttechradar.png'
39
+ destination_file_name= 'lasttechradar.png'
40
+ storage_client = storage.Client()
41
+ bucket = storage_client.bucket(bucket_name)
42
+ blob = bucket.blob(source_blob_name)
43
+ blob.download_to_filename(destination_file_name)
44
+
45
  def getstuff(openapikey):
46
  dateforfilesave=datetime.today().strftime("%d-%m-%Y %I:%M%p")
47
  print(dateforfilesave)
 
163
  clusterstextlist.append("Cluster "+str(i)+"\nTheme:"+response["choices"][0]["text"].replace("\n", "")+'\n'+reviews+'\n'+"-" * 10+'\n\n')
164
 
165
  textlist=[mainlistofanswers[0],"SEPERATOR",mainlistofanswers[1],"SEPERATOR",mainlistofanswers[2],"SEPERATOR",mainlistofanswers[3],"SEPERATOR",desc_tmp,"SEPERATOR","".join(clusterstextlist)]
166
+ ###create file with new info & upload
167
  with open('lastradartext.txt', 'w') as f:
168
  for line in textlist:
169
  f.write(f"{line}\n")
170
+ client = storage.Client()
171
+ bucket = client.get_bucket(bucket_name)
172
+ blob = bucket.blob('lastradartext.txt')
173
+ blob.upload_from_filename('lastradartext.txt')
174
+ print('Came here 8')
175
+
176
+ ###read it and put in output
177
+ source_blob_name = 'lastradartext.txt'
178
+ destination_file_name= 'lastradartext.txt'
179
+ storage_client = storage.Client()
180
+ bucket = storage_client.bucket(bucket_name)
181
+ blob = bucket.blob(source_blob_name)
182
+ blob.download_to_filename(destination_file_name)
183
+
184
  with open('lastradartext.txt', 'r') as file:
185
  data_old = file.read()
186
  value1,value2,value3,value4,value5,value6=data_old.split('SEPERATOR')
187
+
188
+ ###upload image to cloud for next run display
189
+ client = storage.Client()
190
+ bucket = client.get_bucket(bucket_name)
191
+ blob = bucket.blob('lasttechradar.png')
192
+ blob.upload_from_filename('lasttechradar.png')
193
+
194
  return 'lasttechradar.png',mainlistofanswers[0],mainlistofanswers[1],mainlistofanswers[2],mainlistofanswers[3],desc_tmp,"".join(clusterstextlist)
195
 
196
  with gr.Blocks() as demo: