Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import telebot
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Pega as chaves dos Secrets do Hugging Face (mais seguro)
|
| 6 |
+
TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN')
|
| 7 |
+
GEMINI_KEY = os.environ.get('GEMINI_KEY')
|
| 8 |
+
SEU_ID_TELEGRAM = int(os.environ.get('SEU_ID'))
|
| 9 |
+
|
| 10 |
+
# Configurando a Inteligência
|
| 11 |
+
genai.configure(api_key=GEMINI_KEY)
|
| 12 |
+
model = genai.GenerativeModel(
|
| 13 |
+
model_name='gemini-1.5-flash',
|
| 14 |
+
system_instruction="Você é o assistente pessoal do Vitor. Seja inteligente e rápido."
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
bot = telebot.TeleBot(TELEGRAM_TOKEN)
|
| 18 |
+
|
| 19 |
+
@bot.message_handler(func=lambda message: True)
|
| 20 |
+
def responder(message):
|
| 21 |
+
if message.from_user.id != SEU_ID_TELEGRAM:
|
| 22 |
+
return
|
| 23 |
+
try:
|
| 24 |
+
response = model.generate_content(message.text)
|
| 25 |
+
bot.reply_to(message, response.text)
|
| 26 |
+
except Exception as e:
|
| 27 |
+
bot.reply_to(message, f"Erro: {str(e)}")
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
print("Assistente Online!")
|
| 31 |
+
bot.infinity_polling()
|