Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import os
|
| 2 |
import telebot
|
| 3 |
-
import google.generativeai as genai
|
| 4 |
import logging
|
| 5 |
import httpx
|
| 6 |
from flask import Flask, request, jsonify
|
|
@@ -10,7 +9,6 @@ import time
|
|
| 10 |
os.environ['HF_HUB_DISABLE_EXPERIMENTAL_WARNING'] = '1'
|
| 11 |
|
| 12 |
# Configuration
|
| 13 |
-
GOOGLE_API_KEY = 'AIzaSyAYXUMnwmR4nUGDCs97FJJsafcQAPAAuzE'
|
| 14 |
BOT_TOKEN = '7484321656:AAExhpS7sOGMu2BCuPQrDjuXpY3sEQmBgfY'
|
| 15 |
WEBHOOK_SECRET = 'A3%26c8%21jP%23xZ1v*Qw5kL%5E0tR%40u9%25yS6' # URL-encoded secret
|
| 16 |
|
|
@@ -31,36 +29,6 @@ logging.basicConfig(
|
|
| 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 |
app = Flask(__name__)
|
| 65 |
|
| 66 |
@app.route(f'/webhooks/{WEBHOOK_SECRET}', methods=['POST'])
|
|
@@ -75,10 +43,8 @@ def handle_update():
|
|
| 75 |
|
| 76 |
if message_text:
|
| 77 |
try:
|
| 78 |
-
#
|
| 79 |
-
|
| 80 |
-
response = chat_session.send_message(prompt) # Generate response using text and prompt
|
| 81 |
-
response_text = response.text
|
| 82 |
|
| 83 |
# Log the response
|
| 84 |
logger.debug(f"Generated response: {response_text}")
|
|
@@ -88,8 +54,8 @@ def handle_update():
|
|
| 88 |
logger.info(f"Response sent to chat_id {chat_id}")
|
| 89 |
|
| 90 |
except Exception as e:
|
| 91 |
-
logger.error(f"Error during
|
| 92 |
-
error_message = "Sorry, I can't
|
| 93 |
bot.send_message(chat_id, error_message, parse_mode='Markdown')
|
| 94 |
logger.error(f"Error message sent to chat_id {chat_id}")
|
| 95 |
|
|
|
|
| 1 |
import os
|
| 2 |
import telebot
|
|
|
|
| 3 |
import logging
|
| 4 |
import httpx
|
| 5 |
from flask import Flask, request, jsonify
|
|
|
|
| 9 |
os.environ['HF_HUB_DISABLE_EXPERIMENTAL_WARNING'] = '1'
|
| 10 |
|
| 11 |
# Configuration
|
|
|
|
| 12 |
BOT_TOKEN = '7484321656:AAExhpS7sOGMu2BCuPQrDjuXpY3sEQmBgfY'
|
| 13 |
WEBHOOK_SECRET = 'A3%26c8%21jP%23xZ1v*Qw5kL%5E0tR%40u9%25yS6' # URL-encoded secret
|
| 14 |
|
|
|
|
| 29 |
)
|
| 30 |
logger = logging.getLogger(__name__)
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
app = Flask(__name__)
|
| 33 |
|
| 34 |
@app.route(f'/webhooks/{WEBHOOK_SECRET}', methods=['POST'])
|
|
|
|
| 43 |
|
| 44 |
if message_text:
|
| 45 |
try:
|
| 46 |
+
# Simple response mechanism
|
| 47 |
+
response_text = f"You said: {message_text}"
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# Log the response
|
| 50 |
logger.debug(f"Generated response: {response_text}")
|
|
|
|
| 54 |
logger.info(f"Response sent to chat_id {chat_id}")
|
| 55 |
|
| 56 |
except Exception as e:
|
| 57 |
+
logger.error(f"Error during processing: {e}")
|
| 58 |
+
error_message = "Sorry, I can't process this right now."
|
| 59 |
bot.send_message(chat_id, error_message, parse_mode='Markdown')
|
| 60 |
logger.error(f"Error message sent to chat_id {chat_id}")
|
| 61 |
|