Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,22 +31,43 @@ logging.basicConfig(
|
|
| 31 |
)
|
| 32 |
logger = logging.getLogger(__name__)
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
"""Sets the webhook for the Telegram bot."""
|
| 48 |
try:
|
| 49 |
-
response = requests.
|
|
|
|
|
|
|
|
|
|
| 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
|
| 86 |
-
iface = Interface(fn=handle_update, inputs=[], outputs=[])
|
| 87 |
-
|
| 88 |
-
# Run the Gradio app
|
| 89 |
if __name__ == "__main__":
|
| 90 |
-
|
|
|
|
| 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()
|