Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -24,6 +24,7 @@ class GUI:
|
|
24 |
welcome_md = gr.Markdown()
|
25 |
# Updated for Gradio 5 - removed LogoutButton (LoginButton transforms automatically)
|
26 |
login_btn = gr.LoginButton()
|
|
|
27 |
|
28 |
# API Key input section (shown after login)
|
29 |
api_key_section = gr.Column(visible=False)
|
@@ -57,16 +58,21 @@ class GUI:
|
|
57 |
out = gr.Markdown()
|
58 |
inp = gr.File(file_types=['.epub'], visible=False, label="Upload ePub File")
|
59 |
|
60 |
-
# Event handlers -
|
61 |
demo.load(
|
62 |
fn=self.on_load,
|
63 |
outputs=[welcome_md, api_key_section, inp, clear_key_btn]
|
64 |
)
|
65 |
|
66 |
-
#
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
70 |
outputs=[welcome_md, api_key_section, inp, clear_key_btn]
|
71 |
)
|
72 |
|
@@ -187,30 +193,31 @@ class GUI:
|
|
187 |
|
188 |
def on_load(self, request: gr.Request = None):
|
189 |
"""Handle initial page load - Updated for Gradio 5"""
|
190 |
-
|
191 |
-
|
192 |
-
gr.update(value='# ePub Summarization Tool\n\nPlease login to access the tool.'),
|
193 |
-
gr.update(visible=False), # api_key_section
|
194 |
-
gr.update(visible=False), # inp
|
195 |
-
gr.update(visible=False) # clear_key_btn
|
196 |
-
)
|
197 |
-
return self.handle_login_click(request)
|
198 |
|
199 |
-
def
|
200 |
-
"""
|
201 |
try:
|
|
|
|
|
|
|
202 |
if hasattr(request, 'username') and request.username:
|
203 |
return self.handle_user_logged_in(request)
|
204 |
else:
|
205 |
return self.handle_user_not_logged_in()
|
206 |
except Exception as e:
|
207 |
-
print(f"Error
|
208 |
return self.handle_user_not_logged_in()
|
209 |
|
|
|
|
|
|
|
|
|
210 |
def handle_user_not_logged_in(self):
|
211 |
"""Handle when user is not logged in"""
|
212 |
return (
|
213 |
-
gr.update(value='# ePub Summarization Tool\n\nPlease login with Hugging Face to access the tool
|
214 |
gr.update(visible=False), # api_key_section
|
215 |
gr.update(visible=False), # inp
|
216 |
gr.update(visible=False) # clear_key_btn
|
|
|
24 |
welcome_md = gr.Markdown()
|
25 |
# Updated for Gradio 5 - removed LogoutButton (LoginButton transforms automatically)
|
26 |
login_btn = gr.LoginButton()
|
27 |
+
refresh_btn = gr.Button("π Refresh", size="sm", variant="secondary")
|
28 |
|
29 |
# API Key input section (shown after login)
|
30 |
api_key_section = gr.Column(visible=False)
|
|
|
58 |
out = gr.Markdown()
|
59 |
inp = gr.File(file_types=['.epub'], visible=False, label="Upload ePub File")
|
60 |
|
61 |
+
# Event handlers - Fixed for Gradio 5
|
62 |
demo.load(
|
63 |
fn=self.on_load,
|
64 |
outputs=[welcome_md, api_key_section, inp, clear_key_btn]
|
65 |
)
|
66 |
|
67 |
+
# Direct login button event handling
|
68 |
+
login_btn.click(
|
69 |
+
fn=self.handle_login_state_change,
|
70 |
+
outputs=[welcome_md, api_key_section, inp, clear_key_btn]
|
71 |
+
)
|
72 |
+
|
73 |
+
# Manual refresh button for debugging
|
74 |
+
refresh_btn.click(
|
75 |
+
fn=self.handle_login_state_change,
|
76 |
outputs=[welcome_md, api_key_section, inp, clear_key_btn]
|
77 |
)
|
78 |
|
|
|
193 |
|
194 |
def on_load(self, request: gr.Request = None):
|
195 |
"""Handle initial page load - Updated for Gradio 5"""
|
196 |
+
print(f"Page load - Username: {getattr(request, 'username', None)}") # Debug
|
197 |
+
return self.handle_login_state_change(request)
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
+
def handle_login_state_change(self, request: gr.Request = None):
|
200 |
+
"""Handle login state changes - works for both load and login button click"""
|
201 |
try:
|
202 |
+
print(f"Login state check - Username: {getattr(request, 'username', None)}") # Debug
|
203 |
+
print(f"Request attrs: {[attr for attr in dir(request) if not attr.startswith('_')]}") # Debug
|
204 |
+
|
205 |
if hasattr(request, 'username') and request.username:
|
206 |
return self.handle_user_logged_in(request)
|
207 |
else:
|
208 |
return self.handle_user_not_logged_in()
|
209 |
except Exception as e:
|
210 |
+
print(f"Error in login state change: {e}")
|
211 |
return self.handle_user_not_logged_in()
|
212 |
|
213 |
+
def check_login_state(self, request: gr.Request = None):
|
214 |
+
"""Check login state - with debug info"""
|
215 |
+
return self.handle_login_state_change(request)
|
216 |
+
|
217 |
def handle_user_not_logged_in(self):
|
218 |
"""Handle when user is not logged in"""
|
219 |
return (
|
220 |
+
gr.update(value='# ePub Summarization Tool\n\nPlease login with Hugging Face to access the tool.\n\n*If you just logged in, click the π Refresh button above.*'),
|
221 |
gr.update(visible=False), # api_key_section
|
222 |
gr.update(visible=False), # inp
|
223 |
gr.update(visible=False) # clear_key_btn
|