File size: 2,084 Bytes
c71c66a
 
 
 
 
8835321
c71c66a
 
 
8835321
c71c66a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8835321
c71c66a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8835321
c71c66a
8835321
c71c66a
 
 
 
 
 
 
 
8835321
c71c66a
 
8835321
c71c66a
8835321
c71c66a
 
 
8835321
 
 
 
 
 
 
 
 
 
c71c66a
 
 
 
8835321
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import json
import random
from datetime import datetime
import gradio as gr

# ---- Cargar dataset ----
with open("dataset.json", "r") as f:
    dataset = json.load(f)

# ---- Cargar usuarios ----
try:
    with open("users.json", "r") as f:
        users = json.load(f)
except:
    users = {}

def save_users():
    with open("users.json", "w") as f:
        json.dump(users, f, indent=2)

def get_or_create_user(user_id):
    if user_id not in users:
        users[user_id] = {
            "nivel": 1,
            "subscription_active": False,
            "relationship_points": 0,
            "sent_items": [],
            "memory": {}
        }
        save_users()
    return users[user_id]

def select_content(user, platform):
    eligible = []

    for item in dataset:
        if not item["active"]:
            continue
        if platform not in item["platforms"]:
            continue
        if not (item["nivel_min"] <= user["nivel"] <= item["nivel_max"]):
            continue
        if item["id"] in user["sent_items"]:
            continue

        eligible.append(item)

    if not eligible:
        return None

    selected = random.choice(eligible)
    user["sent_items"].append(selected["id"])
    user["relationship_points"] += 5

    if user["relationship_points"] >= 50:
        user["nivel"] = min(user["nivel"] + 1, 5)
        user["relationship_points"] = 0

    save_users()
    return selected

def chat(user_id, message, platform):
    user = get_or_create_user(user_id)
    content = select_content(user, platform)

    response = f"Sofía: Me encanta hablar contigo 💕"

    if content:
        return response, content["url"], content["caption_base"]
    else:
        return response, None, None

iface = gr.Interface(
    fn=chat,
    inputs=[
        gr.Textbox(label="User ID"),
        gr.Textbox(label="Mensaje"),
        gr.Textbox(label="Platform")
    ],
    outputs=[
        gr.Textbox(label="Respuesta"),
        gr.Textbox(label="Media URL"),
        gr.Textbox(label="Caption")
    ],
    title="Sofía Core Engine"
)

iface.launch()