Download app.py from Lisych/Three: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/Lisych/Three/resolve/main/app.py
- Command line
-
hf download hf://spaces/Lisych/Three/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Lisych/Three/resolve/main/app.py
1.15 kB
| import telebot | |
| import requests | |
| from flask import Flask | |
| import threading | |
| # ТВОИ ДАННЫЕ | |
| TOKEN = '8321909394:AAFE6XFSnCRCLByhJZNieWHGwQF0f5VOGqE' | |
| GROQ_KEY = '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' | |
| bot = telebot.TeleBot(TOKEN) | |
| def get_llama_response(text): | |
| url = "https://api.groq.com/openai/v1/chat/completions" | |
| headers = {"Authorization": f"Bearer {GROQ_KEY}", "Content-Type": "application/json"} | |
| data = { | |
| "model": "llama3-8b-8192", | |
| "messages": [{"role": "user", "content": text}] | |
| } | |
| response = requests.post(url, headers=headers, json=data) | |
| return response.json()['choices'][0]['message']['content'] | |
| def handle(message): | |
| try: | |
| answer = get_llama_response(message.text) | |
| bot.reply_to(message, answer) | |
| except Exception as e: | |
| bot.reply_to(message, f"Ошибка: {e}") | |
| app = Flask(__name__) | |
| def index(): return "Бот на Llama 3 запущен!" | |
| if __name__ == "__main__": | |
| threading.Thread(target=bot.infinity_polling, daemon=True).start() | |
| app.run(host='0.0.0.0', port=7860) | |