Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,24 +5,28 @@ import plotly.express as px
|
|
| 5 |
import plotly.io as pio
|
| 6 |
import gradio as gr
|
| 7 |
|
|
|
|
| 8 |
users = {"PM": "Promo123"}
|
| 9 |
campaigns = []
|
| 10 |
sessions = {}
|
| 11 |
|
|
|
|
| 12 |
def login(username, password):
|
| 13 |
if users.get(username) == password:
|
| 14 |
sessions["user"] = username
|
| 15 |
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), f"Willkommen {username}"
|
| 16 |
return gr.update(), gr.update(), gr.update(), "❌ Login fehlgeschlagen"
|
| 17 |
|
|
|
|
| 18 |
def suggest_campaign(product, goal, channel):
|
| 19 |
-
return f"""💡 Idee:
|
| 20 |
Produkt: {product}
|
| 21 |
Ziel: {goal}
|
| 22 |
Kanal: {channel}
|
| 23 |
🚀 Vorschlag:
|
| 24 |
Eine kreative {channel}-Kampagne für {product}, z. B. mit exklusiven Angeboten oder Rabattaktionen."""
|
| 25 |
|
|
|
|
| 26 |
def add_campaign(name, goal, product, channel, start, end, budget, responsible):
|
| 27 |
try:
|
| 28 |
if isinstance(start, str):
|
|
@@ -46,6 +50,7 @@ def add_campaign(name, goal, product, channel, start, end, budget, responsible):
|
|
| 46 |
total = df["Budget (CHF)"].sum()
|
| 47 |
return df, f"💰 Gesamtbudget: CHF {total:.2f}"
|
| 48 |
|
|
|
|
| 49 |
def delete_campaign_by_name(name):
|
| 50 |
global campaigns
|
| 51 |
campaigns = [c for c in campaigns if c["Name"] != name]
|
|
@@ -54,12 +59,14 @@ def delete_campaign_by_name(name):
|
|
| 54 |
names = [c["Name"] for c in campaigns]
|
| 55 |
return df, f"💰 Gesamtbudget: CHF {total:.2f}", gr.update(choices=names, value=None)
|
| 56 |
|
|
|
|
| 57 |
def export_csv():
|
| 58 |
df = pd.DataFrame(campaigns)
|
| 59 |
path = "kampagnen.csv"
|
| 60 |
df.to_csv(path, index=False, sep=";", encoding="utf-8-sig")
|
| 61 |
return path
|
| 62 |
|
|
|
|
| 63 |
def generate_gantt():
|
| 64 |
if not campaigns:
|
| 65 |
return "<i>Keine Kampagnen zum Anzeigen</i>"
|
|
@@ -79,6 +86,7 @@ def generate_gantt():
|
|
| 79 |
except Exception as e:
|
| 80 |
return f"<b>Fehler:</b> {e}"
|
| 81 |
|
|
|
|
| 82 |
with gr.Blocks() as app:
|
| 83 |
# Startseite
|
| 84 |
with gr.Column(visible=True) as start_page:
|
|
@@ -89,10 +97,9 @@ with gr.Blocks() as app:
|
|
| 89 |
# Login-Seite
|
| 90 |
with gr.Column(visible=False) as login_page:
|
| 91 |
gr.Markdown("## 🔐 Login")
|
| 92 |
-
user = gr.Textbox(label="Benutzer"
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
login_btn = gr.Button("Login")
|
| 96 |
login_status = gr.Textbox(interactive=False, visible=False)
|
| 97 |
|
| 98 |
# Kampagnenplaner-Seite
|
|
@@ -104,8 +111,8 @@ with gr.Blocks() as app:
|
|
| 104 |
product = gr.Textbox(label="Produkt")
|
| 105 |
with gr.Row():
|
| 106 |
channel = gr.Dropdown(["Tisch", "Instagram", "E-Mail", "Plakat"], label="Kanal")
|
| 107 |
-
start = Calendar(type="
|
| 108 |
-
end = Calendar(type="
|
| 109 |
with gr.Row():
|
| 110 |
budget = gr.Number(label="Budget (CHF)")
|
| 111 |
responsible = gr.Dropdown(["Markthalle", "Marketing", "PM", "PED"], label="Verantwortlich")
|
|
@@ -125,7 +132,6 @@ with gr.Blocks() as app:
|
|
| 125 |
gr.Markdown("### 📈 Gantt-Visualisierung")
|
| 126 |
gantt_html = gr.HTML()
|
| 127 |
update_chart = gr.Button("🔄 Visualisierung aktualisieren")
|
| 128 |
-
update_chart.click(generate_gantt, outputs=gantt_html)
|
| 129 |
|
| 130 |
# Seitenwechsel
|
| 131 |
def go_to_login():
|
|
@@ -159,4 +165,5 @@ with gr.Blocks() as app:
|
|
| 159 |
# Gantt aktualisieren
|
| 160 |
update_chart.click(generate_gantt, outputs=gantt_html)
|
| 161 |
|
|
|
|
| 162 |
app.launch(share=True)
|
|
|
|
| 5 |
import plotly.io as pio
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
+
# Benutzer und Kampagnen-Daten
|
| 9 |
users = {"PM": "Promo123"}
|
| 10 |
campaigns = []
|
| 11 |
sessions = {}
|
| 12 |
|
| 13 |
+
# Login-Funktion
|
| 14 |
def login(username, password):
|
| 15 |
if users.get(username) == password:
|
| 16 |
sessions["user"] = username
|
| 17 |
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), f"Willkommen {username}"
|
| 18 |
return gr.update(), gr.update(), gr.update(), "❌ Login fehlgeschlagen"
|
| 19 |
|
| 20 |
+
# Kampagnenvorschlag generieren
|
| 21 |
def suggest_campaign(product, goal, channel):
|
| 22 |
+
return f"""💡 Idee:
|
| 23 |
Produkt: {product}
|
| 24 |
Ziel: {goal}
|
| 25 |
Kanal: {channel}
|
| 26 |
🚀 Vorschlag:
|
| 27 |
Eine kreative {channel}-Kampagne für {product}, z. B. mit exklusiven Angeboten oder Rabattaktionen."""
|
| 28 |
|
| 29 |
+
# Kampagne hinzufügen
|
| 30 |
def add_campaign(name, goal, product, channel, start, end, budget, responsible):
|
| 31 |
try:
|
| 32 |
if isinstance(start, str):
|
|
|
|
| 50 |
total = df["Budget (CHF)"].sum()
|
| 51 |
return df, f"💰 Gesamtbudget: CHF {total:.2f}"
|
| 52 |
|
| 53 |
+
# Kampagne löschen
|
| 54 |
def delete_campaign_by_name(name):
|
| 55 |
global campaigns
|
| 56 |
campaigns = [c for c in campaigns if c["Name"] != name]
|
|
|
|
| 59 |
names = [c["Name"] for c in campaigns]
|
| 60 |
return df, f"💰 Gesamtbudget: CHF {total:.2f}", gr.update(choices=names, value=None)
|
| 61 |
|
| 62 |
+
# CSV-Export
|
| 63 |
def export_csv():
|
| 64 |
df = pd.DataFrame(campaigns)
|
| 65 |
path = "kampagnen.csv"
|
| 66 |
df.to_csv(path, index=False, sep=";", encoding="utf-8-sig")
|
| 67 |
return path
|
| 68 |
|
| 69 |
+
# Gantt-Diagramm generieren
|
| 70 |
def generate_gantt():
|
| 71 |
if not campaigns:
|
| 72 |
return "<i>Keine Kampagnen zum Anzeigen</i>"
|
|
|
|
| 86 |
except Exception as e:
|
| 87 |
return f"<b>Fehler:</b> {e}"
|
| 88 |
|
| 89 |
+
# Gradio-App
|
| 90 |
with gr.Blocks() as app:
|
| 91 |
# Startseite
|
| 92 |
with gr.Column(visible=True) as start_page:
|
|
|
|
| 97 |
# Login-Seite
|
| 98 |
with gr.Column(visible=False) as login_page:
|
| 99 |
gr.Markdown("## 🔐 Login")
|
| 100 |
+
user = gr.Textbox(label="Benutzer")
|
| 101 |
+
pw = gr.Textbox(label="Passwort", type="password")
|
| 102 |
+
login_btn = gr.Button("Login")
|
|
|
|
| 103 |
login_status = gr.Textbox(interactive=False, visible=False)
|
| 104 |
|
| 105 |
# Kampagnenplaner-Seite
|
|
|
|
| 111 |
product = gr.Textbox(label="Produkt")
|
| 112 |
with gr.Row():
|
| 113 |
channel = gr.Dropdown(["Tisch", "Instagram", "E-Mail", "Plakat"], label="Kanal")
|
| 114 |
+
start = Calendar(type="date", label="Startdatum")
|
| 115 |
+
end = Calendar(type="date", label="Enddatum")
|
| 116 |
with gr.Row():
|
| 117 |
budget = gr.Number(label="Budget (CHF)")
|
| 118 |
responsible = gr.Dropdown(["Markthalle", "Marketing", "PM", "PED"], label="Verantwortlich")
|
|
|
|
| 132 |
gr.Markdown("### 📈 Gantt-Visualisierung")
|
| 133 |
gantt_html = gr.HTML()
|
| 134 |
update_chart = gr.Button("🔄 Visualisierung aktualisieren")
|
|
|
|
| 135 |
|
| 136 |
# Seitenwechsel
|
| 137 |
def go_to_login():
|
|
|
|
| 165 |
# Gantt aktualisieren
|
| 166 |
update_chart.click(generate_gantt, outputs=gantt_html)
|
| 167 |
|
| 168 |
+
# App starten
|
| 169 |
app.launch(share=True)
|