Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,11 +3,11 @@ import random
|
|
| 3 |
from datetime import datetime
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
# Cargar dataset
|
| 7 |
with open("dataset.json", "r") as f:
|
| 8 |
dataset = json.load(f)
|
| 9 |
|
| 10 |
-
# Cargar usuarios
|
| 11 |
try:
|
| 12 |
with open("users.json", "r") as f:
|
| 13 |
users = json.load(f)
|
|
@@ -27,6 +27,7 @@ def get_or_create_user(user_id):
|
|
| 27 |
"sent_items": [],
|
| 28 |
"memory": {}
|
| 29 |
}
|
|
|
|
| 30 |
return users[user_id]
|
| 31 |
|
| 32 |
def select_content(user, platform):
|
|
@@ -48,34 +49,41 @@ def select_content(user, platform):
|
|
| 48 |
return None
|
| 49 |
|
| 50 |
selected = random.choice(eligible)
|
| 51 |
-
selected["global_usage_count"] += 1
|
| 52 |
user["sent_items"].append(selected["id"])
|
| 53 |
user["relationship_points"] += 5
|
| 54 |
|
| 55 |
-
if user["relationship_points"] > 50:
|
| 56 |
user["nivel"] = min(user["nivel"] + 1, 5)
|
|
|
|
| 57 |
|
| 58 |
save_users()
|
| 59 |
-
|
| 60 |
return selected
|
| 61 |
|
| 62 |
def chat(user_id, message, platform):
|
| 63 |
user = get_or_create_user(user_id)
|
| 64 |
-
|
| 65 |
content = select_content(user, platform)
|
| 66 |
|
| 67 |
-
|
| 68 |
|
| 69 |
if content:
|
| 70 |
-
return
|
| 71 |
else:
|
| 72 |
-
return
|
| 73 |
|
| 74 |
iface = gr.Interface(
|
| 75 |
fn=chat,
|
| 76 |
-
inputs=[
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
title="Sofía Core Engine"
|
| 79 |
)
|
| 80 |
|
| 81 |
iface.launch()
|
|
|
|
|
|
| 3 |
from datetime import datetime
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
# ---- Cargar dataset ----
|
| 7 |
with open("dataset.json", "r") as f:
|
| 8 |
dataset = json.load(f)
|
| 9 |
|
| 10 |
+
# ---- Cargar usuarios ----
|
| 11 |
try:
|
| 12 |
with open("users.json", "r") as f:
|
| 13 |
users = json.load(f)
|
|
|
|
| 27 |
"sent_items": [],
|
| 28 |
"memory": {}
|
| 29 |
}
|
| 30 |
+
save_users()
|
| 31 |
return users[user_id]
|
| 32 |
|
| 33 |
def select_content(user, platform):
|
|
|
|
| 49 |
return None
|
| 50 |
|
| 51 |
selected = random.choice(eligible)
|
|
|
|
| 52 |
user["sent_items"].append(selected["id"])
|
| 53 |
user["relationship_points"] += 5
|
| 54 |
|
| 55 |
+
if user["relationship_points"] >= 50:
|
| 56 |
user["nivel"] = min(user["nivel"] + 1, 5)
|
| 57 |
+
user["relationship_points"] = 0
|
| 58 |
|
| 59 |
save_users()
|
|
|
|
| 60 |
return selected
|
| 61 |
|
| 62 |
def chat(user_id, message, platform):
|
| 63 |
user = get_or_create_user(user_id)
|
|
|
|
| 64 |
content = select_content(user, platform)
|
| 65 |
|
| 66 |
+
response = f"Sofía: Me encanta hablar contigo 💕"
|
| 67 |
|
| 68 |
if content:
|
| 69 |
+
return response, content["url"], content["caption_base"]
|
| 70 |
else:
|
| 71 |
+
return response, None, None
|
| 72 |
|
| 73 |
iface = gr.Interface(
|
| 74 |
fn=chat,
|
| 75 |
+
inputs=[
|
| 76 |
+
gr.Textbox(label="User ID"),
|
| 77 |
+
gr.Textbox(label="Mensaje"),
|
| 78 |
+
gr.Textbox(label="Platform")
|
| 79 |
+
],
|
| 80 |
+
outputs=[
|
| 81 |
+
gr.Textbox(label="Respuesta"),
|
| 82 |
+
gr.Textbox(label="Media URL"),
|
| 83 |
+
gr.Textbox(label="Caption")
|
| 84 |
+
],
|
| 85 |
title="Sofía Core Engine"
|
| 86 |
)
|
| 87 |
|
| 88 |
iface.launch()
|
| 89 |
+
|