measmonysuon commited on
Commit
c538ed4
·
verified ·
1 Parent(s): c5cf26a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -18
app.py CHANGED
@@ -31,22 +31,43 @@ logging.basicConfig(
31
  )
32
  logger = logging.getLogger(__name__)
33
 
34
- def set_webhook():
35
- """Sets the webhook for the Telegram bot."""
36
- try:
37
- response = requests.get(f"https://api.telegram.org/bot{BOT_TOKEN}/setWebhook?url={WEBHOOK_URL}")
38
- result = response.json()
39
- if result.get('ok'):
40
- logger.info("Webhook set successfully.")
41
- else:
42
- logger.error(f"Failed to set webhook: {result}")
43
- except requests.exceptions.RequestException as e:
44
- logger.error(f"Request exception: {e}")
 
 
 
 
 
45
 
46
- def set_webhook():
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  """Sets the webhook for the Telegram bot."""
48
  try:
49
- response = requests.get(f"https://api.telegram.org/bot{BOT_TOKEN}/setWebhook?url={WEBHOOK_URL}")
 
 
 
50
  result = response.json()
51
  if result.get('ok'):
52
  logger.info("Webhook set successfully.")
@@ -82,10 +103,8 @@ async def handle_update(payload: WebhookPayload) -> None:
82
  bot.send_message(chat_id, error_message, parse_mode='Markdown')
83
  logger.error(f"Error message sent to chat_id {chat_id}")
84
 
85
- # Initialize the Gradio interface
86
- iface = Interface(fn=handle_update, inputs=[], outputs=[])
87
-
88
- # Run the Gradio app
89
  if __name__ == "__main__":
90
- set_webhook() # Set the webhook for Telegram
 
91
  iface.launch()
 
31
  )
32
  logger = logging.getLogger(__name__)
33
 
34
+ # Set up Google Generative AI
35
+ genai.configure(api_key=GOOGLE_API_KEY)
36
+
37
+ generation_config = {
38
+ "temperature": 1,
39
+ "top_p": 0.95,
40
+ "top_k": 64,
41
+ "max_output_tokens": 8192,
42
+ "response_mime_type": "text/plain",
43
+ }
44
+
45
+ model = genai.GenerativeModel(
46
+ model_name="gemini-1.5-pro",
47
+ generation_config=generation_config,
48
+ system_instruction="Please respond to user input"
49
+ )
50
 
51
+ chat_session = model.start_chat(
52
+ history=[
53
+ {"role": "user", "parts": ["hi\n"]},
54
+ {"role": "model", "parts": ["Hello! 👋 How can I help you today? 😊 \n"]},
55
+ {"role": "user", "parts": ["I am looking for photo booth service?"]},
56
+ {"role": "model", "parts": ["That's great! 🎉 I can definitely help you with information about Aforative Media's photo booth services. \n\nTo give you the most relevant information, could you tell me a little more about what you're looking for? ..."]},
57
+ {"role": "user", "parts": ["How much for photo booth services?"]},
58
+ {"role": "model", "parts": ["You're smart to ask about pricing upfront! 😉 \n\nAforative Media's Mr. & Ms. Booth photo booth services start at **USD 390 for a minimum of 2 hours**. ..."]},
59
+ {"role": "user", "parts": ["How about videography service?"]},
60
+ {"role": "model", "parts": ["You're thinking about capturing the memories on film too? Excellent choice! Videography adds a whole other dimension to remembering special events. \n\nAforative Media offers excellent videography services, and just like their photo booths, their videography packages are competitively priced and flexible. ..."]},
61
+ ]
62
+ )
63
+
64
+ def set_telegram_webhook():
65
  """Sets the webhook for the Telegram bot."""
66
  try:
67
+ response = requests.post(
68
+ f"https://api.telegram.org/bot{BOT_TOKEN}/setWebhook",
69
+ data={"url": WEBHOOK_URL}
70
+ )
71
  result = response.json()
72
  if result.get('ok'):
73
  logger.info("Webhook set successfully.")
 
103
  bot.send_message(chat_id, error_message, parse_mode='Markdown')
104
  logger.error(f"Error message sent to chat_id {chat_id}")
105
 
106
+ # Initialize and run the Gradio app
 
 
 
107
  if __name__ == "__main__":
108
+ set_telegram_webhook() # Set the webhook for Telegram
109
+ iface = Interface(fn=handle_update, inputs=[], outputs=[])
110
  iface.launch()