Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,16 +58,20 @@ def gemini_response(prompt):
|
|
| 58 |
except Exception as e:
|
| 59 |
return f"⚠️ Gemini error: {e}"
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
history
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
return history, history
|
| 68 |
|
| 69 |
# ======================
|
| 70 |
-
#
|
| 71 |
# ======================
|
| 72 |
|
| 73 |
css = """
|
|
@@ -86,6 +90,9 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as app:
|
|
| 86 |
|
| 87 |
gr.Markdown("## 🔐 Welcome to ZeppFusion Login System")
|
| 88 |
|
|
|
|
|
|
|
|
|
|
| 89 |
with gr.Tabs():
|
| 90 |
|
| 91 |
# -------------------
|
|
@@ -106,51 +113,46 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as app:
|
|
| 106 |
reg_status = gr.Textbox(label="Status", interactive=False)
|
| 107 |
reg_btn = gr.Button("Signup")
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
|
| 125 |
-
clear.click(lambda: [], None, chatbot)
|
| 126 |
-
|
| 127 |
-
# -------------------
|
| 128 |
-
# BUTTON ACTIONS
|
| 129 |
-
# -------------------
|
| 130 |
-
|
| 131 |
-
# Signup action
|
| 132 |
-
reg_btn.click(
|
| 133 |
-
signup,
|
| 134 |
-
inputs=[reg_user, reg_pw],
|
| 135 |
-
outputs=reg_status
|
| 136 |
-
)
|
| 137 |
-
|
| 138 |
-
# Login action
|
| 139 |
-
def login_action(username, password):
|
| 140 |
-
res = login(username, password)
|
| 141 |
-
if res == "SUCCESS":
|
| 142 |
-
return "✅ Амжилттай нэвтэрлээ!", True, gr.update(visible=True)
|
| 143 |
-
return res, False, gr.update(visible=False)
|
| 144 |
-
|
| 145 |
-
log_btn.click(
|
| 146 |
-
login_action,
|
| 147 |
-
inputs=[log_user, log_pw],
|
| 148 |
-
outputs=[log_status, logged_in, chat_ui]
|
| 149 |
-
)
|
| 150 |
-
|
| 151 |
-
# -----------------------
|
| 152 |
# RUN
|
| 153 |
-
#
|
| 154 |
|
| 155 |
if __name__ == "__main__":
|
| 156 |
app.launch()
|
|
|
|
| 58 |
except Exception as e:
|
| 59 |
return f"⚠️ Gemini error: {e}"
|
| 60 |
|
| 61 |
+
# ======================
|
| 62 |
+
# 🌙 CHAT FUNCTION
|
| 63 |
+
# ======================
|
| 64 |
+
|
| 65 |
+
def chat_fn(prompt, history):
|
| 66 |
+
history = history or []
|
| 67 |
+
history.append({"role": "user", "content": prompt})
|
| 68 |
+
time.sleep(0.5) # simulate typing
|
| 69 |
+
reply = gemini_response(prompt)
|
| 70 |
+
history.append({"role": "bot", "content": reply})
|
| 71 |
return history, history
|
| 72 |
|
| 73 |
# ======================
|
| 74 |
+
# 🌟 UI CSS
|
| 75 |
# ======================
|
| 76 |
|
| 77 |
css = """
|
|
|
|
| 90 |
|
| 91 |
gr.Markdown("## 🔐 Welcome to ZeppFusion Login System")
|
| 92 |
|
| 93 |
+
# ======================
|
| 94 |
+
# Tabs: Login / Signup
|
| 95 |
+
# ======================
|
| 96 |
with gr.Tabs():
|
| 97 |
|
| 98 |
# -------------------
|
|
|
|
| 113 |
reg_status = gr.Textbox(label="Status", interactive=False)
|
| 114 |
reg_btn = gr.Button("Signup")
|
| 115 |
|
| 116 |
+
# ======================
|
| 117 |
+
# Chat UI (hidden initially)
|
| 118 |
+
# ======================
|
| 119 |
+
with gr.Group(visible=False) as chat_ui:
|
| 120 |
+
with gr.Row():
|
| 121 |
+
gr.Image(value=logo_path, show_label=False)
|
| 122 |
+
gr.Markdown("## ZeppFusion AI Chat")
|
| 123 |
+
chatbot = gr.Chatbot(type="messages")
|
| 124 |
+
msg = gr.Textbox(placeholder="Таны асуулт...", lines=1)
|
| 125 |
+
clear = gr.Button("🗑️ Clear History")
|
| 126 |
+
msg.submit(chat_fn, inputs=[msg, chatbot], outputs=[chatbot, chatbot])
|
| 127 |
+
clear.click(lambda: [], None, chatbot)
|
| 128 |
+
|
| 129 |
+
# ======================
|
| 130 |
+
# BUTTON ACTIONS
|
| 131 |
+
# ======================
|
| 132 |
+
|
| 133 |
+
# Signup
|
| 134 |
+
reg_btn.click(
|
| 135 |
+
signup,
|
| 136 |
+
inputs=[reg_user, reg_pw],
|
| 137 |
+
outputs=reg_status
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
# Login
|
| 141 |
+
def login_action(username, password):
|
| 142 |
+
res = login(username, password)
|
| 143 |
+
if res == "SUCCESS":
|
| 144 |
+
return "✅ Амжилттай нэвтэрлээ!", gr.update(visible=True)
|
| 145 |
+
return res, gr.update(visible=False)
|
| 146 |
+
|
| 147 |
+
log_btn.click(
|
| 148 |
+
login_action,
|
| 149 |
+
inputs=[log_user, log_pw],
|
| 150 |
+
outputs=[log_status, chat_ui]
|
| 151 |
+
)
|
| 152 |
|
| 153 |
+
# ======================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
# RUN
|
| 155 |
+
# ======================
|
| 156 |
|
| 157 |
if __name__ == "__main__":
|
| 158 |
app.launch()
|