Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -778,8 +778,7 @@ def generate_response_stream(prompt, temperature=0.7, backend=None, max_tokens=2
|
|
| 778 |
final_tokens_per_sec = tokens_generated / elapsed if elapsed > 0 else 0
|
| 779 |
yield "", False, final_tokens_per_sec, final_tokens_per_sec, False
|
| 780 |
|
| 781 |
-
|
| 782 |
-
# PART 3 - Continue from Part 2
|
| 783 |
|
| 784 |
if __name__ == "__main__":
|
| 785 |
import gradio as gr
|
|
@@ -870,9 +869,10 @@ if __name__ == "__main__":
|
|
| 870 |
html += '</div>'
|
| 871 |
return html
|
| 872 |
|
| 873 |
-
user_session = gr.State({})
|
| 874 |
-
|
| 875 |
with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="slate")) as demo:
|
|
|
|
|
|
|
|
|
|
| 876 |
gr.HTML('<div class="announcement-banner">🔐 <strong>SAM-X-1 V3.0 - SECURE ACCESS</strong> 🔐<br>✨ Sign in to unlock AI-powered conversations!<br>🆓 FREE: Nano & Mini unlimited, Fast 10/3h, Large 8/3h<br>⭐ PLUS: Nano/Mini/Fast unlimited, Large 20/3h<br>💎 PRO: Everything unlimited!</div>')
|
| 877 |
|
| 878 |
with gr.Tabs() as main_tabs:
|
|
@@ -948,11 +948,12 @@ if __name__ == "__main__":
|
|
| 948 |
submit_upgrade_btn = gr.Button("Submit Request", variant="primary")
|
| 949 |
upgrade_msg = gr.Markdown("")
|
| 950 |
|
|
|
|
| 951 |
def handle_login(username, password):
|
| 952 |
success, user_data = authenticate_user(username, password)
|
| 953 |
if success:
|
| 954 |
-
return user_data, f"✅ Welcome back, {username}!", ""
|
| 955 |
-
return {}, "❌ Invalid credentials!", ""
|
| 956 |
|
| 957 |
def handle_signup(username, email, password):
|
| 958 |
if len(username) < 3:
|
|
@@ -1075,19 +1076,23 @@ if __name__ == "__main__":
|
|
| 1075 |
return f"{'✅' if success else '❌'} {msg}"
|
| 1076 |
|
| 1077 |
def handle_logout():
|
| 1078 |
-
return {}, "Please sign in", ""
|
| 1079 |
|
| 1080 |
-
|
|
|
|
| 1081 |
signup_btn.click(handle_signup, [signup_username, signup_email, signup_password], [signup_msg])
|
| 1082 |
chat_tab.select(load_user_interface, [user_session], [user_info, limits_display, admin_panel, model_selector, max_tokens_slider])
|
|
|
|
| 1083 |
send_outputs = [msg_input, chat_html, speed_display, send_btn, stop_btn]
|
| 1084 |
send_btn.click(send_message_handler, [msg_input, show_thinking_checkbox, temperature_slider, model_selector, max_tokens_slider, user_session], send_outputs)
|
| 1085 |
msg_input.submit(send_message_handler, [msg_input, show_thinking_checkbox, temperature_slider, model_selector, max_tokens_slider, user_session], send_outputs)
|
|
|
|
| 1086 |
stop_btn.click(stop_generation_handler, outputs=[speed_display, send_btn, stop_btn])
|
| 1087 |
clear_btn.click(clear_chat, outputs=[chat_html, speed_display, send_btn, stop_btn])
|
| 1088 |
upgrade_btn.click(show_upgrade_panel, outputs=[upgrade_panel])
|
| 1089 |
submit_upgrade_btn.click(submit_upgrade_request, [upgrade_plan_choice, upgrade_reason, user_session], [upgrade_msg])
|
| 1090 |
-
logout_btn.click(handle_logout, outputs=[user_session, user_info, chat_html
|
|
|
|
| 1091 |
refresh_users_btn.click(load_all_users, outputs=[users_table])
|
| 1092 |
refresh_requests_btn.click(load_pending_requests, outputs=[requests_table])
|
| 1093 |
update_plan_btn.click(admin_update_plan, [admin_username, admin_new_plan], [admin_msg])
|
|
@@ -1106,70 +1111,9 @@ if __name__ == "__main__":
|
|
| 1106 |
| **Large Model** | 8 msgs/3h | 20 msgs/3h | ✅ Unlimited |
|
| 1107 |
| **Model Selection** | 🤖 Auto only | ✅ Manual choice | ✅ Manual choice |
|
| 1108 |
| **Max Tokens** | 256 | 384 | 512 |
|
| 1109 |
-
| **Reset Period** | 3 hours | 3 hours | 3 hours |
|
| 1110 |
-
|
| 1111 |
-
### 🎯 How It Works
|
| 1112 |
-
|
| 1113 |
-
1. **Rolling 3-Hour Window**: Your limits reset 3 hours after you start using the service
|
| 1114 |
-
2. **Australia Timezone**: All times are in Australian Eastern Time (Sydney)
|
| 1115 |
-
3. **Smart Auto-Selection**: FREE users get optimal model selection based on query complexity
|
| 1116 |
-
4. **Flexible Limits**: Nano & Mini are always available for quick questions
|
| 1117 |
-
5. **Upgrade Requests**: Request PLUS or PRO access through the chat interface
|
| 1118 |
-
|
| 1119 |
-
### 💡 Tips for FREE Users
|
| 1120 |
-
|
| 1121 |
-
- **Use Nano & Mini freely** - Perfect for most questions and coding tasks (30-40 tok/s!)
|
| 1122 |
-
- **Save Fast/Large for complex tasks** - You get 10 Fast and 8 Large messages per 3h window
|
| 1123 |
-
- **Let Auto mode decide** - It intelligently picks the right model for your question
|
| 1124 |
-
- **Watch your reset timer** - Plan your usage around the 3-hour window
|
| 1125 |
-
|
| 1126 |
-
### 🔐 Admin Access
|
| 1127 |
-
|
| 1128 |
-
- **Username**: `admin`
|
| 1129 |
-
- **Password**: `admin123`
|
| 1130 |
-
- Admin can manage users, approve upgrades, and reset limits
|
| 1131 |
-
|
| 1132 |
-
### 🚀 V3.0 Features
|
| 1133 |
-
|
| 1134 |
-
- ✅ **User Authentication** - Secure sign in/sign up system
|
| 1135 |
-
- ✅ **Three-Tier Plans** - FREE, PLUS, PRO with different limits
|
| 1136 |
-
- ✅ **Rolling 3-Hour Limits** - Fair usage based on activity
|
| 1137 |
-
- ✅ **Admin Panel** - Full user management and upgrade approval
|
| 1138 |
-
- ✅ **Smart Model Selection** - Auto mode for FREE, manual for PLUS/PRO
|
| 1139 |
-
- ✅ **Usage Tracking** - Monitor your message limits in real-time
|
| 1140 |
-
- ✅ **Australia Timezone** - All times displayed in AEST/AEDT
|
| 1141 |
-
- ✅ **Upgrade Requests** - In-app upgrade request system
|
| 1142 |
-
- ✅ **Per-Model Limits** - Separate counters for Nano, Mini, Fast, Large
|
| 1143 |
-
- ✅ **Dynamic Batching** - Faster UI updates (2-8 token batching)
|
| 1144 |
-
|
| 1145 |
-
### 📝 How to Use
|
| 1146 |
-
|
| 1147 |
-
**Step 1**: Create an account (Sign Up tab)
|
| 1148 |
-
**Step 2**: Sign in with your credentials
|
| 1149 |
-
**Step 3**: Go to Chat tab and start chatting!
|
| 1150 |
-
**Step 4**: Monitor your limits in the limits panel
|
| 1151 |
-
**Step 5**: Request upgrade if you need more access
|
| 1152 |
-
|
| 1153 |
-
### 🎓 Example Queries by Plan
|
| 1154 |
-
|
| 1155 |
-
**FREE Plan (Auto Mode):**
|
| 1156 |
-
- "What is Python?" → Nano (instant, unlimited)
|
| 1157 |
-
- "Write a hello world function" → Mini (fast, unlimited)
|
| 1158 |
-
- "Explain object-oriented programming" → Fast (uses 1 of 10)
|
| 1159 |
-
- "Prove the Pythagorean theorem" → Large (uses 1 of 8)
|
| 1160 |
-
|
| 1161 |
-
**PLUS/PRO (Manual Selection):**
|
| 1162 |
-
- Choose any model based on your needs
|
| 1163 |
-
- PLUS gets 20 Large messages per 3h
|
| 1164 |
-
- PRO gets unlimited everything!
|
| 1165 |
-
|
| 1166 |
-
### 📧 Support
|
| 1167 |
-
|
| 1168 |
-
For questions or issues, contact the admin through the upgrade request system!
|
| 1169 |
-
|
| 1170 |
-
---
|
| 1171 |
|
| 1172 |
-
|
|
|
|
| 1173 |
""")
|
| 1174 |
|
| 1175 |
-
demo.launch(debug=True, share=
|
|
|
|
| 778 |
final_tokens_per_sec = tokens_generated / elapsed if elapsed > 0 else 0
|
| 779 |
yield "", False, final_tokens_per_sec, final_tokens_per_sec, False
|
| 780 |
|
| 781 |
+
# PART 3 - Continue from Part 2 - FIXED VERSION
|
|
|
|
| 782 |
|
| 783 |
if __name__ == "__main__":
|
| 784 |
import gradio as gr
|
|
|
|
| 869 |
html += '</div>'
|
| 870 |
return html
|
| 871 |
|
|
|
|
|
|
|
| 872 |
with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="slate")) as demo:
|
| 873 |
+
# Session state
|
| 874 |
+
user_session = gr.State({})
|
| 875 |
+
|
| 876 |
gr.HTML('<div class="announcement-banner">🔐 <strong>SAM-X-1 V3.0 - SECURE ACCESS</strong> 🔐<br>✨ Sign in to unlock AI-powered conversations!<br>🆓 FREE: Nano & Mini unlimited, Fast 10/3h, Large 8/3h<br>⭐ PLUS: Nano/Mini/Fast unlimited, Large 20/3h<br>💎 PRO: Everything unlimited!</div>')
|
| 877 |
|
| 878 |
with gr.Tabs() as main_tabs:
|
|
|
|
| 948 |
submit_upgrade_btn = gr.Button("Submit Request", variant="primary")
|
| 949 |
upgrade_msg = gr.Markdown("")
|
| 950 |
|
| 951 |
+
# Event handlers
|
| 952 |
def handle_login(username, password):
|
| 953 |
success, user_data = authenticate_user(username, password)
|
| 954 |
if success:
|
| 955 |
+
return user_data, f"✅ Welcome back, {username}!", ""
|
| 956 |
+
return {}, "❌ Invalid credentials!", ""
|
| 957 |
|
| 958 |
def handle_signup(username, email, password):
|
| 959 |
if len(username) < 3:
|
|
|
|
| 1076 |
return f"{'✅' if success else '❌'} {msg}"
|
| 1077 |
|
| 1078 |
def handle_logout():
|
| 1079 |
+
return {}, "Please sign in", ""
|
| 1080 |
|
| 1081 |
+
# Wire up events
|
| 1082 |
+
login_btn.click(handle_login, [login_username, login_password], [user_session, login_msg, chat_html])
|
| 1083 |
signup_btn.click(handle_signup, [signup_username, signup_email, signup_password], [signup_msg])
|
| 1084 |
chat_tab.select(load_user_interface, [user_session], [user_info, limits_display, admin_panel, model_selector, max_tokens_slider])
|
| 1085 |
+
|
| 1086 |
send_outputs = [msg_input, chat_html, speed_display, send_btn, stop_btn]
|
| 1087 |
send_btn.click(send_message_handler, [msg_input, show_thinking_checkbox, temperature_slider, model_selector, max_tokens_slider, user_session], send_outputs)
|
| 1088 |
msg_input.submit(send_message_handler, [msg_input, show_thinking_checkbox, temperature_slider, model_selector, max_tokens_slider, user_session], send_outputs)
|
| 1089 |
+
|
| 1090 |
stop_btn.click(stop_generation_handler, outputs=[speed_display, send_btn, stop_btn])
|
| 1091 |
clear_btn.click(clear_chat, outputs=[chat_html, speed_display, send_btn, stop_btn])
|
| 1092 |
upgrade_btn.click(show_upgrade_panel, outputs=[upgrade_panel])
|
| 1093 |
submit_upgrade_btn.click(submit_upgrade_request, [upgrade_plan_choice, upgrade_reason, user_session], [upgrade_msg])
|
| 1094 |
+
logout_btn.click(handle_logout, outputs=[user_session, user_info, chat_html])
|
| 1095 |
+
|
| 1096 |
refresh_users_btn.click(load_all_users, outputs=[users_table])
|
| 1097 |
refresh_requests_btn.click(load_pending_requests, outputs=[requests_table])
|
| 1098 |
update_plan_btn.click(admin_update_plan, [admin_username, admin_new_plan], [admin_msg])
|
|
|
|
| 1111 |
| **Large Model** | 8 msgs/3h | 20 msgs/3h | ✅ Unlimited |
|
| 1112 |
| **Model Selection** | 🤖 Auto only | ✅ Manual choice | ✅ Manual choice |
|
| 1113 |
| **Max Tokens** | 256 | 384 | 512 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1114 |
|
| 1115 |
+
### 🔐 Default Admin: `admin` / `admin123`
|
| 1116 |
+
### 🆓 Sign up for FREE account - Nano & Mini unlimited!
|
| 1117 |
""")
|
| 1118 |
|
| 1119 |
+
demo.launch(debug=True, share=False, server_name="0.0.0.0", server_port=7860)
|