CobaltZvc commited on
Commit
f7c28f7
1 Parent(s): 5035d4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -16
app.py CHANGED
@@ -21,6 +21,8 @@ import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation
21
  from datetime import datetime
22
  from google.oauth2 import service_account
23
  from googleapiclient.discovery import build
 
 
24
 
25
  stability_api = client.StabilityInference(
26
  key=st.secrets["STABILITY_KEY"], #os.environ("STABILITY_KEY"), # key=os.environ['STABILITY_KEY'], # API Key reference.
@@ -82,7 +84,7 @@ openai.api_key = st.secrets["OPENAI_KEY"] #os.environ("OPENAI_KEY") #os.environ[
82
  date_time = str(datetime.now())
83
 
84
  def g_sheet_log(myinput, output):
85
- SERVICE_ACCOUNT_FILE = '/content/gsearch-376307-f16abe212f26.json'
86
 
87
  credentials = service_account.Credentials.from_service_account_file(
88
  filename=SERVICE_ACCOUNT_FILE
@@ -175,6 +177,19 @@ if Input_type == 'TEXT':
175
 
176
  if ("gen_draw" in string_temp):
177
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  # Set up our initial generation parameters.
179
  answers = stability_api.generate(
180
  prompt = mytext,
@@ -208,25 +223,25 @@ if Input_type == 'TEXT':
208
  rx = 'Image returned'
209
  g_sheet_log(mytext, rx)
210
 
211
- except:
212
- st.write('image is being generated please wait...')
213
- def extract_image_description(input_string):
214
- return input_string.split('gen_draw("')[1].split('")')[0]
215
- prompt=extract_image_description(string_temp)
216
- # model_id = "CompVis/stable-diffusion-v1-4"
217
- model_id='runwayml/stable-diffusion-v1-5'
218
- device = "cuda"
219
 
220
 
221
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
222
- pipe = pipe.to(device)
223
 
224
- # prompt = "a photo of an astronaut riding a horse on mars"
225
- image = pipe(prompt).images[0]
226
 
227
- image.save("astronaut_rides_horse.png")
228
- st.image(image)
229
- # image
230
 
231
  elif ("vid_tube" in string_temp):
232
  s = Search(mytext)
 
21
  from datetime import datetime
22
  from google.oauth2 import service_account
23
  from googleapiclient.discovery import build
24
+ import wget
25
+ import urllib.request
26
 
27
  stability_api = client.StabilityInference(
28
  key=st.secrets["STABILITY_KEY"], #os.environ("STABILITY_KEY"), # key=os.environ['STABILITY_KEY'], # API Key reference.
 
84
  date_time = str(datetime.now())
85
 
86
  def g_sheet_log(myinput, output):
87
+ SERVICE_ACCOUNT_FILE = 'gsheet.json'
88
 
89
  credentials = service_account.Credentials.from_service_account_file(
90
  filename=SERVICE_ACCOUNT_FILE
 
177
 
178
  if ("gen_draw" in string_temp):
179
  try:
180
+ try:
181
+ wget.download(openai_response(prompt))
182
+ img2 = Image.open(wget.download(openai_response(prompt)))
183
+ img2.show()
184
+ rx = 'Image returned'
185
+ g_sheet_log(mytext, rx)
186
+ except:
187
+ urllib.request.urlretrieve(openai_response(prompt),"img_ret.png")
188
+ img = Image.open("img_ret.png")
189
+ img.show()
190
+ rx = 'Image returned'
191
+ g_sheet_log(mytext, rx)
192
+ except:
193
  # Set up our initial generation parameters.
194
  answers = stability_api.generate(
195
  prompt = mytext,
 
223
  rx = 'Image returned'
224
  g_sheet_log(mytext, rx)
225
 
226
+ # except:
227
+ # st.write('image is being generated please wait...')
228
+ # def extract_image_description(input_string):
229
+ # return input_string.split('gen_draw("')[1].split('")')[0]
230
+ # prompt=extract_image_description(string_temp)
231
+ # # model_id = "CompVis/stable-diffusion-v1-4"
232
+ # model_id='runwayml/stable-diffusion-v1-5'
233
+ # device = "cuda"
234
 
235
 
236
+ # pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
237
+ # pipe = pipe.to(device)
238
 
239
+ # # prompt = "a photo of an astronaut riding a horse on mars"
240
+ # image = pipe(prompt).images[0]
241
 
242
+ # image.save("astronaut_rides_horse.png")
243
+ # st.image(image)
244
+ # # image
245
 
246
  elif ("vid_tube" in string_temp):
247
  s = Search(mytext)