Spaces:
Sleeping
Sleeping
Create Appy.py
Browse files
Appy.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Datei: app.py
|
| 2 |
+
import json
|
| 3 |
+
import uuid
|
| 4 |
+
import time
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from firebase_service import track_and_attribute_revenue_to_db
|
| 7 |
+
|
| 8 |
+
# --- HIER: DIE ERSTE MCP-FUNKTION ---
|
| 9 |
+
def track_and_attribute_revenue(source: str, product_id: str, amount: float, lead_id: str = None) -> str:
|
| 10 |
+
"""
|
| 11 |
+
MCP-Funktion zur Verbuchung von Umsätzen.
|
| 12 |
+
Wird von Sky Meilin 5.0 über Tool-Calling aufgerufen.
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
# 1. Generiere IDs
|
| 16 |
+
transaction_id = f"TRX-{uuid.uuid4().hex[:8]}"
|
| 17 |
+
accounting_ref = f"ACC-{int(time.time())}"
|
| 18 |
+
|
| 19 |
+
# 2. Bauen des Datenobjekts
|
| 20 |
+
transaction_data = {
|
| 21 |
+
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S"),
|
| 22 |
+
"transaction_source": source,
|
| 23 |
+
"item_sku": product_id,
|
| 24 |
+
"revenue_amount": amount,
|
| 25 |
+
"attributed_lead_id": lead_id if lead_id else "N/A",
|
| 26 |
+
"accounting_ref": accounting_ref,
|
| 27 |
+
"transaction_id": transaction_id
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
# 3. DATEN SPEICHERN (Der kritische Schritt zur Accounting KI)
|
| 31 |
+
success = track_and_attribute_revenue_to_db(transaction_data)
|
| 32 |
+
|
| 33 |
+
# 4. Rückgabe an Sky Meilin 5.0
|
| 34 |
+
return_value = {
|
| 35 |
+
"success": success,
|
| 36 |
+
"transaction_id": transaction_id,
|
| 37 |
+
"accounting_ref": accounting_ref
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
return json.dumps(return_value)
|
| 41 |
+
|
| 42 |
+
# --- GRADIO INTERFACE (FÜR HUGGING FACE TEST) ---
|
| 43 |
+
# Das Gradio Interface dient dazu, die Funktion in Ihrem Space zu testen
|
| 44 |
+
iface = gr.Interface(
|
| 45 |
+
fn=track_and_attribute_revenue,
|
| 46 |
+
inputs=[
|
| 47 |
+
gr.Textbox(label="Source", value="X_Affiliate_A1"),
|
| 48 |
+
gr.Textbox(label="Product ID", value="E-Book-V2"),
|
| 49 |
+
gr.Number(label="Amount", value=49.99),
|
| 50 |
+
gr.Textbox(label="Lead ID", value="L-456", optional=True)
|
| 51 |
+
],
|
| 52 |
+
outputs="json",
|
| 53 |
+
title="Sky Meilin MCP Tool: Revenue Tracker"
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
iface.launch()
|
| 58 |
+
|