Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,7 @@ from PIL import Image
|
|
| 23 |
from PIL import ImageOps
|
| 24 |
from PIL import Image, ImageDraw, ImageFont
|
| 25 |
from io import BytesIO
|
|
|
|
| 26 |
|
| 27 |
import gcsfs
|
| 28 |
fs = gcsfs.GCSFileSystem(project='createinsightsproject',token='anon')
|
|
@@ -33,8 +34,9 @@ with fs.open('trends_chrome_extension_bucket/lastradartext.txt', 'rb') as file:
|
|
| 33 |
data_old = file.read()
|
| 34 |
print(data_old)
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
value1,value2,value3,value4,value5,value6=str(data_old).split('SEPERATOR')
|
| 40 |
|
|
@@ -160,33 +162,28 @@ def getstuff(openapikey):
|
|
| 160 |
clusterstextlist.append("Cluster "+str(i)+"\nTheme:"+response["choices"][0]["text"].replace("\n", "")+'\n'+reviews+'\n'+"-" * 10+'\n\n')
|
| 161 |
|
| 162 |
textlist=[mainlistofanswers[0],"SEPERATOR",mainlistofanswers[1],"SEPERATOR",mainlistofanswers[2],"SEPERATOR",mainlistofanswers[3],"SEPERATOR",desc_tmp,"SEPERATOR","".join(clusterstextlist)]
|
| 163 |
-
###create file with new info & upload
|
| 164 |
with open('lastradartext.txt', 'w') as f:
|
| 165 |
for line in textlist:
|
| 166 |
f.write(f"{line}\n")
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
|
|
|
| 171 |
print('Came here 8')
|
| 172 |
|
| 173 |
###read it and put in output
|
| 174 |
-
source_blob_name = 'lastradartext.txt'
|
| 175 |
-
destination_file_name= 'lastradartext.txt'
|
| 176 |
-
storage_client = storage.Client()
|
| 177 |
-
bucket = storage_client.bucket(bucket_name)
|
| 178 |
-
blob = bucket.blob(source_blob_name)
|
| 179 |
-
blob.download_to_filename(destination_file_name)
|
| 180 |
|
| 181 |
with open('lastradartext.txt', 'r') as file:
|
| 182 |
data_old = file.read()
|
| 183 |
value1,value2,value3,value4,value5,value6=data_old.split('SEPERATOR')
|
| 184 |
|
| 185 |
###upload image to cloud for next run display
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
|
| 191 |
return 'lasttechradar.png',mainlistofanswers[0],mainlistofanswers[1],mainlistofanswers[2],mainlistofanswers[3],desc_tmp,"".join(clusterstextlist)
|
| 192 |
|
|
|
|
| 23 |
from PIL import ImageOps
|
| 24 |
from PIL import Image, ImageDraw, ImageFont
|
| 25 |
from io import BytesIO
|
| 26 |
+
import requests
|
| 27 |
|
| 28 |
import gcsfs
|
| 29 |
fs = gcsfs.GCSFileSystem(project='createinsightsproject',token='anon')
|
|
|
|
| 34 |
data_old = file.read()
|
| 35 |
print(data_old)
|
| 36 |
|
| 37 |
+
img_data = requests.get('https://storage.googleapis.com/trends_chrome_extension_bucket/lasttechradar.png').content
|
| 38 |
+
with open('lasttechradar.png', 'wb') as handler:
|
| 39 |
+
handler.write(img_data)
|
| 40 |
|
| 41 |
value1,value2,value3,value4,value5,value6=str(data_old).split('SEPERATOR')
|
| 42 |
|
|
|
|
| 162 |
clusterstextlist.append("Cluster "+str(i)+"\nTheme:"+response["choices"][0]["text"].replace("\n", "")+'\n'+reviews+'\n'+"-" * 10+'\n\n')
|
| 163 |
|
| 164 |
textlist=[mainlistofanswers[0],"SEPERATOR",mainlistofanswers[1],"SEPERATOR",mainlistofanswers[2],"SEPERATOR",mainlistofanswers[3],"SEPERATOR",desc_tmp,"SEPERATOR","".join(clusterstextlist)]
|
| 165 |
+
###create file with new info locally & upload to bucket
|
| 166 |
with open('lastradartext.txt', 'w') as f:
|
| 167 |
for line in textlist:
|
| 168 |
f.write(f"{line}\n")
|
| 169 |
+
|
| 170 |
+
with fs.open('trends_chrome_extension_bucket/lastradartext.txt', 'wb') as file:
|
| 171 |
+
for line in textlist:
|
| 172 |
+
file.write(f"{line}\n")
|
| 173 |
+
|
| 174 |
print('Came here 8')
|
| 175 |
|
| 176 |
###read it and put in output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
with open('lastradartext.txt', 'r') as file:
|
| 179 |
data_old = file.read()
|
| 180 |
value1,value2,value3,value4,value5,value6=data_old.split('SEPERATOR')
|
| 181 |
|
| 182 |
###upload image to cloud for next run display
|
| 183 |
+
with open('lasttechradar.png','rb') as image_file:
|
| 184 |
+
image_string = image_file.read()
|
| 185 |
+
with fs.open('trends_chrome_extension_bucket/lasttechradar.png', 'wb') as file:
|
| 186 |
+
file.write(image_string)
|
| 187 |
|
| 188 |
return 'lasttechradar.png',mainlistofanswers[0],mainlistofanswers[1],mainlistofanswers[2],mainlistofanswers[3],desc_tmp,"".join(clusterstextlist)
|
| 189 |
|