Spaces:
Runtime error
Runtime error
import gradio as gr | |
import requests | |
import gspread | |
from oauth2client.service_account import ServiceAccountCredentials | |
# API Keys | |
DEEPSEEK_API_URL = "https://api.deepseek.com/v1/chat/completions" # Убедитесь, что URL актуален | |
DEEPSEEK_API_KEY = "sk-c8fdcfbac1984ab6b2fefd0215874f11" # Замените на ваш API-ключ DeepSeek | |
GEO_API = "https://ipinfo.io?token=bb7f2bd1388934" | |
AFFILIATE_LINK = "https://1whhzm.top?p=41xd" | |
# Подключение Google Sheets | |
scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"] | |
creds = ServiceAccountCredentials.from_json_keyfile_name("credentials.json", scope) | |
client = gspread.authorize(creds) | |
sheet = client.open("CPA_Affiliate_Analytics").sheet1 | |
# Функция определения GEO | |
def get_user_geo(): | |
response = requests.get(GEO_API) | |
return response.json().get("country", "Unknown") | |
# Генерация текста через DeepSeek API | |
def generate_reply(user_input): | |
headers = { | |
"Authorization": f"Bearer {DEEPSEEK_API_KEY}", | |
"Content-Type": "application/json" | |
} | |
data = { | |
"model": "deepseek-chat", # Укажите модель DeepSeek | |
"messages": [ | |
{"role": "system", "content": "Ты AI-бот, который продает казино офферы."}, | |
{"role": "user", "content": user_input} | |
] | |
} | |
response = requests.post(DEEPSEEK_API_URL, headers=headers, json=data) | |
if response.status_code == 200: | |
return response.json()["choices"][0]["message"]["content"] | |
else: | |
return "Ошибка при генерации ответа." | |
# Функция обработки запроса | |
def chatbot(user_input): | |
geo = get_user_geo() | |
reply_text = generate_reply(user_input) | |
# Сохраняем данные в Google Sheets | |
sheet.append_row([geo, user_input, reply_text]) | |
return f"🌍 GEO: {geo}\n🤖 AI: {reply_text}\n🎰 Бонус: {AFFILIATE_LINK}" | |
# Интерфейс Gradio | |
iface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="AI-CPA Бот") | |
# Запуск | |
iface.launch() |