Skydata001 commited on
Commit
5dcbdcb
·
verified ·
1 Parent(s): a10aaa9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -10
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- import streamlit.components.v1 as components # <<< جديد: لاستقبال الرسائل
3
  from PIL import Image
4
  import torch
5
  from torchvision import transforms
@@ -55,10 +55,10 @@ window.addEventListener('message', (event) => {
55
  # ستقوم هذه الدالة بإرجاع القيمة (authenticated: true) عند نجاح الاستماع
56
  auth_result = components.html(auth_listener_html, height=0, width=0)
57
 
 
58
  # إذا أرسل المستمع نتيجة إيجابية، قم بتحديث حالة الجلسة
59
- if auth_result and auth_result.get("authenticated"):
60
  st.session_state.authenticated = True
61
-
62
  # --- نهاية خطوة المصادقة ---
63
 
64
 
@@ -66,14 +66,63 @@ if auth_result and auth_result.get("authenticated"):
66
  if st.session_state.authenticated:
67
 
68
  # --- 2. كود التصميم (CSS) ---
69
- # (نفس كود CSS الذي كان لديك، تم نقله إلى هنا ليعمل فقط بعد النجاح)
70
  CUSTOM_CSS = """
71
  <style>
72
  /* ... (نفس كود CSS بالكامل) ... */
73
  body, [data-testid="stAppViewContainer"], [data-testid="stHeader"] {
74
- background-color: #121212 !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  }
76
- /* ... إلخ ... */
77
  </style>
78
  """
79
  st.markdown(CUSTOM_CSS, unsafe_allow_html=True)
@@ -164,9 +213,6 @@ if st.session_state.authenticated:
164
  selected_tab = st.sidebar.radio(loc['input_method'], [loc['tab_upload'], loc['tab_url'], loc['tab_file']])
165
 
166
  # --- 8. منطق التبويبات ---
167
- # (هنا نضع كل منطق التبويبات الثلاثة: tab_upload, tab_url, tab_file)
168
- # ... (الكود الخاص بك كما هو) ...
169
-
170
  if selected_tab == loc['tab_upload']:
171
  uploaded_file = st.file_uploader(loc['upload_prompt'], type=["jpg", "jpeg", "png"])
172
  if uploaded_file is not None:
@@ -220,7 +266,7 @@ if st.session_state.authenticated:
220
  except Exception as e:
221
  st.error(f"{loc['generic_error']} {e}")
222
 
223
- # --- <<< جديد: إذا فشلت المصادقة ---
224
  else:
225
  # إذا لم تنجح المصادقة (st.session_state.authenticated بقيت False)
226
  # سيعرض رسالة الخطأ هذه بدلاً من التطبيق
 
1
  import streamlit as st
2
+ import streamlit.components.v1 as components # لاستقبال الرسائل
3
  from PIL import Image
4
  import torch
5
  from torchvision import transforms
 
55
  # ستقوم هذه الدالة بإرجاع القيمة (authenticated: true) عند نجاح الاستماع
56
  auth_result = components.html(auth_listener_html, height=0, width=0)
57
 
58
+ # --- <<< هذا هو السطر الذي تم تصحيحه ---
59
  # إذا أرسل المستمع نتيجة إيجابية، قم بتحديث حالة الجلسة
60
+ if auth_result and "authenticated" in auth_result and auth_result["authenticated"]:
61
  st.session_state.authenticated = True
 
62
  # --- نهاية خطوة المصادقة ---
63
 
64
 
 
66
  if st.session_state.authenticated:
67
 
68
  # --- 2. كود التصميم (CSS) ---
 
69
  CUSTOM_CSS = """
70
  <style>
71
  /* ... (نفس كود CSS بالكامل) ... */
72
  body, [data-testid="stAppViewContainer"], [data-testid="stHeader"] {
73
+ background-color: #121212 !important; color: #e0e0e0 !important;
74
+ }
75
+ [data-testid="stHeader"] {
76
+ background-color: #1e1e1e !important; border-bottom: 1px solid #333;
77
+ }
78
+ h1, h2, h3, h4, h5, h6 { color: #ffffff !important; }
79
+ p, label, [data-testid="stMarkdownContainer"] { color: #e0e0e0 !important; }
80
+
81
+ /* ... (باقي كود CSS الخاص بك) ... */
82
+ [data-testid="stSidebar"][aria-expanded="true"] {
83
+ background-color: #1e1e1e !important; border-right: 1px solid #333 !important;
84
+ }
85
+ [data-testid="stSidebar"][aria-expanded="true"] [data-testid="stRadio"] label {
86
+ background-color: #2a2a2a; padding: 10px; border-radius: 5px;
87
+ margin: 5px 0; transition: all 0.3s ease;
88
+ }
89
+ [data-testid="stSidebar"][aria-expanded="true"] [data-testid="stRadio"] label:hover {
90
+ background-color: #333; color: #007bff;
91
+ }
92
+ [data-testid="stSidebar"][aria-expanded="true"] [data-testid="stRadio"] input:checked + div {
93
+ color: #007bff;
94
+ }
95
+ [data-testid="stDownloadButton"] > button {
96
+ background-color: #007bff !important; color: #ffffff !important;
97
+ border: none !important; border-radius: 5px !important;
98
+ font-weight: bold !important; padding: 12px 20px !important;
99
+ transition: all 0.3s ease !important; width: 100%;
100
+ }
101
+ [data-testid="stDownloadButton"] > button:hover {
102
+ background-color: #0056b3 !important; transform: scale(1.03) !important;
103
+ }
104
+ [data-testid="stFileUploader"] section {
105
+ background-color: #1e1e1e !important; border: 1px dashed #333 !important;
106
+ border-radius: 8px !important;
107
+ }
108
+ [data-testid="stFileUploader"] section > button {
109
+ background-color: #007bff !important; color: #ffffff !important;
110
+ border: none !important; border-radius: 5px !important;
111
+ font-weight: bold !important; transition: all 0.3s ease !important;
112
+ }
113
+ [data-testid="stFileUploader"] section > button:hover {
114
+ background-color: #0056b3 !important; transform: scale(1.03) !important;
115
+ }
116
+ [data-testid="stFileUploader"] label { color: #ffffff !important; }
117
+ [data-testid="stFileUploader"] section [data-testid="stMarkdownContainer"] p {
118
+ color: #aaa !important;
119
+ }
120
+ [data-testid="stImage"] figcaption { color: #aaa !important; }
121
+ [data-testid="stSpinner"] > div { color: #e0e0e0 !important; }
122
+ [data-testid="stTextInput"] input {
123
+ background-color: #1e1e1e !important; color: #e0e0e0 !important;
124
+ border: 1px solid #333 !important; border-radius: 5px !important;
125
  }
 
126
  </style>
127
  """
128
  st.markdown(CUSTOM_CSS, unsafe_allow_html=True)
 
213
  selected_tab = st.sidebar.radio(loc['input_method'], [loc['tab_upload'], loc['tab_url'], loc['tab_file']])
214
 
215
  # --- 8. منطق التبويبات ---
 
 
 
216
  if selected_tab == loc['tab_upload']:
217
  uploaded_file = st.file_uploader(loc['upload_prompt'], type=["jpg", "jpeg", "png"])
218
  if uploaded_file is not None:
 
266
  except Exception as e:
267
  st.error(f"{loc['generic_error']} {e}")
268
 
269
+ # --- إذا فشلت المصادقة ---
270
  else:
271
  # إذا لم تنجح المصادقة (st.session_state.authenticated بقيت False)
272
  # سيعرض رسالة الخطأ هذه بدلاً من التطبيق