rbn2008k commited on
Commit
cecc149
·
verified ·
1 Parent(s): f0a18bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -174,7 +174,7 @@ async def get_completion(event, user_id, prompt):
174
  async for chunk in completion:
175
  if chunk.choices[0].delta.content is not None:
176
  message += chunk.choices[0].delta.content
177
- bot_message.edit(message)
178
  except Exception as e:
179
  message = "Whoops!"
180
  print(e)
@@ -204,20 +204,19 @@ async def handle_message(event):
204
  async with client.action(event.chat_id, 'typing'):
205
  await asyncio.sleep(1)
206
  bot_id = await get_bot_id()
 
 
 
 
 
 
 
 
 
 
 
207
  try:
208
- user_id = event.chat_id
209
- if event.sender_id == bot_id:
210
- return
211
- user_message = event.raw_text
212
- if event.photo:
213
- photo = await event.download_media()
214
- if photo:
215
- image_description = describe_image(photo, user_message)
216
- user_message += f"\n\nI sent you an image. Content of the image: {image_description}"
217
- if user_message.startswith('/start') or user_message.startswith('/help') or user_message.startswith('/reset'):
218
- return
219
- response = await get_completion(event, user_id, user_message)
220
- await event.respond(response)
221
  except Exception as e:
222
  print(f"An error occurred: {e}")
223
  await event.respond("Whoopsie!")
@@ -229,6 +228,8 @@ def launch_gradio():
229
  - Scarlett is a girl residing in Telegram
230
  - She can chat with you without any censorship.
231
  - Head over to https://t.me/Scarlett_Rogue_isNotBot
 
 
232
  """
233
  with gr.Blocks() as demo:
234
  gr.Markdown(f"""
 
174
  async for chunk in completion:
175
  if chunk.choices[0].delta.content is not None:
176
  message += chunk.choices[0].delta.content
177
+ await bot_message.edit(message)
178
  except Exception as e:
179
  message = "Whoops!"
180
  print(e)
 
204
  async with client.action(event.chat_id, 'typing'):
205
  await asyncio.sleep(1)
206
  bot_id = await get_bot_id()
207
+ if event.sender_id == bot_id:
208
+ return
209
+ user_id = event.chat_id
210
+ user_message = event.raw_text
211
+ if event.photo:
212
+ photo = await event.download_media()
213
+ if photo:
214
+ image_description = describe_image(photo, user_message)
215
+ user_message += f"\n\nI sent you an image. Content of the image: {image_description}"
216
+ if user_message.startswith(('/start', '/help', '/reset')):
217
+ return
218
  try:
219
+ await get_completion(event, user_id, user_message)
 
 
 
 
 
 
 
 
 
 
 
 
220
  except Exception as e:
221
  print(f"An error occurred: {e}")
222
  await event.respond("Whoopsie!")
 
228
  - Scarlett is a girl residing in Telegram
229
  - She can chat with you without any censorship.
230
  - Head over to https://t.me/Scarlett_Rogue_isNotBot
231
+
232
+ - Thanks to https://glhf.chat for powering this!
233
  """
234
  with gr.Blocks() as demo:
235
  gr.Markdown(f"""