Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,19 +5,16 @@ import plotly.express as px
|
|
| 5 |
import plotly.io as pio
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
-
# Benutzer
|
| 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=True), f"
|
| 18 |
-
return gr.update(
|
| 19 |
|
| 20 |
-
# Vorschlag mit KI
|
| 21 |
def suggest_campaign(product, goal, channel):
|
| 22 |
return f"""💡 Idee:
|
| 23 |
Produkt: {product}
|
|
@@ -26,16 +23,15 @@ Kanal: {channel}
|
|
| 26 |
🚀 Vorschlag:
|
| 27 |
Eine kreative {channel}-Kampagne für {product}, z. B. mit exklusiven Angeboten oder Rabattaktionen."""
|
| 28 |
|
| 29 |
-
# Kampagne speichern
|
| 30 |
def add_campaign(name, goal, product, channel, start, end, budget, responsible):
|
| 31 |
try:
|
| 32 |
if isinstance(start, str):
|
| 33 |
start = datetime.datetime.strptime(start, "%Y-%m-%d")
|
| 34 |
if isinstance(end, str):
|
| 35 |
-
end = datetime.datetime.strptime(end, "%Y-%m-%d")
|
| 36 |
except Exception as e:
|
| 37 |
return pd.DataFrame(campaigns), f"❌ Ungültiges Datum: {e}"
|
| 38 |
-
|
| 39 |
campaigns.append({
|
| 40 |
"Name": name,
|
| 41 |
"Ziel": goal,
|
|
@@ -50,87 +46,15 @@ def add_campaign(name, goal, product, channel, start, end, budget, responsible):
|
|
| 50 |
total = df["Budget (CHF)"].sum()
|
| 51 |
return df, f"💰 Gesamtbudget: CHF {total:.2f}"
|
| 52 |
|
| 53 |
-
# CSV Export
|
| 54 |
def export_csv():
|
| 55 |
path = "kampagnen.csv"
|
| 56 |
pd.DataFrame(campaigns).to_csv(path, index=False)
|
| 57 |
return path
|
| 58 |
|
| 59 |
-
# Gantt-Chart
|
| 60 |
def generate_gantt():
|
| 61 |
if not campaigns:
|
| 62 |
return "<i>Keine Kampagnen zum Anzeigen</i>"
|
| 63 |
df = pd.DataFrame(campaigns)
|
| 64 |
df["Start"] = pd.to_datetime(df["Start"])
|
| 65 |
-
df["Ende"] = pd.to_datetime(df["
|
| 66 |
-
try:
|
| 67 |
-
fig = px.timeline(df, x_start="Start", x_end="Ende", y="Name", color="Verantwortlich", title="📊 Kampagnenübersicht")
|
| 68 |
-
fig.update_yaxes(autorange="reversed")
|
| 69 |
-
fig.update_layout(height=400, margin=dict(l=20, r=20, t=30, b=20))
|
| 70 |
-
return pio.to_html(fig, full_html=False, include_plotlyjs='cdn')
|
| 71 |
-
except Exception as e:
|
| 72 |
-
return f"<b>Fehler:</b> {e}"
|
| 73 |
-
|
| 74 |
-
# Mehr Infos anzeigen
|
| 75 |
-
def show_info():
|
| 76 |
-
return gr.update(visible=True)
|
| 77 |
-
|
| 78 |
-
# Navigation zur Login-Seite
|
| 79 |
-
def go_to_login():
|
| 80 |
-
return gr.update(visible=False), gr.update(visible=True)
|
| 81 |
-
|
| 82 |
-
# Gradio UI
|
| 83 |
-
with gr.Blocks() as app:
|
| 84 |
-
### STARTSEITE ###
|
| 85 |
-
with gr.Column(visible=True) as start_page:
|
| 86 |
-
gr.Image("/mnt/data/1595297d-4de2-4607-b7e4-94bfac1ecc49.png", show_label=False, scale=0.3)
|
| 87 |
-
gr.Markdown("## 👋 Willkommen beim Promo-Planer")
|
| 88 |
-
gr.Markdown("Planen, verwalten und visualisieren Sie Ihre Marketingkampagnen effizient.")
|
| 89 |
-
with gr.Row():
|
| 90 |
-
info_btn = gr.Button("ℹ️ Mehr Infos")
|
| 91 |
-
start_btn = gr.Button("🚀 Loslegen")
|
| 92 |
-
info_popup = gr.Textbox(value="📌 Mit diesem Tool können Sie Marketingkampagnen mit Start- und Enddatum, Budgets und Zuständigkeiten planen und verwalten. Nutzen Sie die KI-Vorschläge für Ideen und visualisieren Sie Zeitverläufe mit Gantt-Charts.", visible=False, interactive=False, lines=5)
|
| 93 |
-
info_btn.click(show_info, outputs=info_popup)
|
| 94 |
-
start_btn.click(go_to_login, outputs=[start_page, login_page])
|
| 95 |
-
|
| 96 |
-
### LOGIN ###
|
| 97 |
-
with gr.Column(visible=False) as login_page:
|
| 98 |
-
gr.Markdown("## 🔐 Login")
|
| 99 |
-
with gr.Row():
|
| 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)
|
| 104 |
-
login_btn.click(login, [user, pw], [login_page, planner_page, login_status])
|
| 105 |
-
|
| 106 |
-
### HAUPTSEITE ###
|
| 107 |
-
with gr.Column(visible=False) as planner_page:
|
| 108 |
-
gr.Markdown("## 📣 Kampagnen-Planung")
|
| 109 |
-
with gr.Row():
|
| 110 |
-
name = gr.Textbox(label="Kampagnenname")
|
| 111 |
-
goal = gr.Dropdown(["Verkaufsförderung", "Werbung", "Event"], label="Ziel")
|
| 112 |
-
product = gr.Textbox(label="Produkt")
|
| 113 |
-
with gr.Row():
|
| 114 |
-
channel = gr.Dropdown(["Tisch", "Instagram", "E-Mail", "Plakat"], label="Kanal")
|
| 115 |
-
start = Calendar(type="datetime", label="Startdatum")
|
| 116 |
-
end = Calendar(type="datetime", label="Enddatum")
|
| 117 |
-
with gr.Row():
|
| 118 |
-
budget = gr.Number(label="Budget (CHF)")
|
| 119 |
-
responsible = gr.Dropdown(["Markthalle", "Marketing", "PM", "PED"], label="Verantwortlich")
|
| 120 |
-
suggest_btn = gr.Button("💡 KI-Vorschlag")
|
| 121 |
-
idea = gr.Textbox(label="Kampagnenidee")
|
| 122 |
-
submit_btn = gr.Button("✅ Speichern")
|
| 123 |
-
output_table = gr.Dataframe()
|
| 124 |
-
budget_total = gr.Textbox(label="Budget Gesamt", interactive=False)
|
| 125 |
-
export_btn = gr.Button("📤 Export CSV")
|
| 126 |
-
gr.Markdown("### 📈 Gantt-Visualisierung")
|
| 127 |
-
gantt_html = gr.HTML()
|
| 128 |
-
update_chart = gr.Button("🔄 Visualisierung aktualisieren")
|
| 129 |
-
|
| 130 |
-
suggest_btn.click(suggest_campaign, [product, goal, channel], idea)
|
| 131 |
-
submit_btn.click(add_campaign, [name, goal, product, channel, start, end, budget, responsible], [output_table, budget_total])
|
| 132 |
-
export_btn.click(export_csv, outputs=None)
|
| 133 |
-
update_chart.click(generate_gantt, outputs=gantt_html)
|
| 134 |
|
| 135 |
-
# App starten
|
| 136 |
-
app.launch(share=True)
|
|
|
|
| 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}
|
|
|
|
| 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):
|
| 29 |
start = datetime.datetime.strptime(start, "%Y-%m-%d")
|
| 30 |
if isinstance(end, str):
|
| 31 |
+
end = datetime.datetime.strptime(end, "%Y-%m-%d")
|
| 32 |
except Exception as e:
|
| 33 |
return pd.DataFrame(campaigns), f"❌ Ungültiges Datum: {e}"
|
| 34 |
+
|
| 35 |
campaigns.append({
|
| 36 |
"Name": name,
|
| 37 |
"Ziel": goal,
|
|
|
|
| 46 |
total = df["Budget (CHF)"].sum()
|
| 47 |
return df, f"💰 Gesamtbudget: CHF {total:.2f}"
|
| 48 |
|
|
|
|
| 49 |
def export_csv():
|
| 50 |
path = "kampagnen.csv"
|
| 51 |
pd.DataFrame(campaigns).to_csv(path, index=False)
|
| 52 |
return path
|
| 53 |
|
|
|
|
| 54 |
def generate_gantt():
|
| 55 |
if not campaigns:
|
| 56 |
return "<i>Keine Kampagnen zum Anzeigen</i>"
|
| 57 |
df = pd.DataFrame(campaigns)
|
| 58 |
df["Start"] = pd.to_datetime(df["Start"])
|
| 59 |
+
df["Ende"] = pd.to_datetime(df["End_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
|
|
|
|
|