Spaces:
Sleeping
Sleeping
| # Datei: app.py | |
| import json | |
| import uuid | |
| import time | |
| import gradio as gr | |
| from firebase_service import track_and_attribute_revenue_to_db | |
| # --- HIER: DIE ERSTE MCP-FUNKTION --- | |
| def track_and_attribute_revenue(source: str, product_id: str, amount: float, lead_id: str = None) -> str: | |
| """ | |
| MCP-Funktion zur Verbuchung von Umsätzen. | |
| Wird von Sky Meilin 5.0 über Tool-Calling aufgerufen. | |
| """ | |
| # 1. Generiere IDs | |
| transaction_id = f"TRX-{uuid.uuid4().hex[:8]}" | |
| accounting_ref = f"ACC-{int(time.time())}" | |
| # 2. Bauen des Datenobjekts | |
| transaction_data = { | |
| "timestamp": time.strftime("%Y-%m-%d %H:%M:%S"), | |
| "transaction_source": source, | |
| "item_sku": product_id, | |
| "revenue_amount": amount, | |
| "attributed_lead_id": lead_id if lead_id else "N/A", | |
| "accounting_ref": accounting_ref, | |
| "transaction_id": transaction_id | |
| } | |
| # 3. DATEN SPEICHERN (Der kritische Schritt zur Accounting KI) | |
| success = track_and_attribute_revenue_to_db(transaction_data) | |
| # 4. Rückgabe an Sky Meilin 5.0 | |
| return_value = { | |
| "success": success, | |
| "transaction_id": transaction_id, | |
| "accounting_ref": accounting_ref | |
| } | |
| return json.dumps(return_value) | |
| # --- GRADIO INTERFACE (FÜR HUGGING FACE TEST) --- | |
| # Das Gradio Interface dient dazu, die Funktion in Ihrem Space zu testen | |
| iface = gr.Interface( | |
| fn=track_and_attribute_revenue, | |
| inputs=[ | |
| gr.Textbox(label="Source", value="X_Affiliate_A1"), | |
| gr.Textbox(label="Product ID", value="E-Book-V2"), | |
| gr.Number(label="Amount", value=49.99), | |
| gr.Textbox(label="Lead ID", value="L-456", optional=True) | |
| ], | |
| outputs="json", | |
| title="Sky Meilin MCP Tool: Revenue Tracker" | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |