File size: 2,166 Bytes
c39a54b
275c612
 
 
 
 
 
 
560910b
 
275c612
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c39a54b
275c612
c39a54b
275c612
 
 
 
c39a54b
275c612
 
c39a54b
275c612
c39a54b
275c612
 
c39a54b
275c612
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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()