Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,9 +59,9 @@ class GUI:
|
|
| 59 |
inp = gr.File(file_types=['.epub'], visible=False)
|
| 60 |
|
| 61 |
# Event handlers
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
api_key_btn.click(
|
| 66 |
self.set_api_key,
|
| 67 |
inputs=[api_key_input, remember_key],
|
|
@@ -151,21 +151,33 @@ class GUI:
|
|
| 151 |
print(f"Error deleting saved key: {e}")
|
| 152 |
return False
|
| 153 |
|
| 154 |
-
def on_load(self,
|
| 155 |
-
"""Handle initial page load"""
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
| 157 |
return (
|
| 158 |
gr.update(value='# ePub Summarization Tool\n\nPlease login to access the tool.'),
|
| 159 |
gr.update(visible=False), # api_key_section
|
| 160 |
gr.update(visible=False), # inp
|
| 161 |
gr.update(visible=False) # clear_key_btn
|
| 162 |
)
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
-
def
|
| 166 |
-
"""Handle user login"""
|
| 167 |
if not profile:
|
| 168 |
-
return self.
|
| 169 |
|
| 170 |
self.current_user = self._get_user_id(profile)
|
| 171 |
user_name = profile.name if hasattr(profile, 'name') else profile.username
|
|
@@ -190,8 +202,8 @@ class GUI:
|
|
| 190 |
gr.update(visible=False) # clear_key_btn
|
| 191 |
)
|
| 192 |
|
| 193 |
-
def
|
| 194 |
-
"""Handle user logout"""
|
| 195 |
self.current_user = None
|
| 196 |
self.api_key = None
|
| 197 |
self.client = None
|
|
@@ -334,7 +346,10 @@ class GUI:
|
|
| 334 |
print(f"Error calling Poe API: {e}")
|
| 335 |
return f"Error processing text: {str(e)}"
|
| 336 |
|
| 337 |
-
def process(self, file,
|
|
|
|
|
|
|
|
|
|
| 338 |
if profile is None:
|
| 339 |
return gr.update(value='⚠️ Please login to access the tool.')
|
| 340 |
|
|
|
|
| 59 |
inp = gr.File(file_types=['.epub'], visible=False)
|
| 60 |
|
| 61 |
# Event handlers
|
| 62 |
+
demo.load(self.on_load, None, [welcome_md, api_key_section, inp, clear_key_btn])
|
| 63 |
+
# Note: Login/logout events are handled automatically by Gradio
|
| 64 |
+
# We use demo.load to check login status on page load/refresh
|
| 65 |
api_key_btn.click(
|
| 66 |
self.set_api_key,
|
| 67 |
inputs=[api_key_input, remember_key],
|
|
|
|
| 151 |
print(f"Error deleting saved key: {e}")
|
| 152 |
return False
|
| 153 |
|
| 154 |
+
def on_load(self, request: gr.Request = None):
|
| 155 |
+
"""Handle initial page load and login status check"""
|
| 156 |
+
# Get user info from request if available
|
| 157 |
+
profile = getattr(request, 'username', None) if request else None
|
| 158 |
+
|
| 159 |
+
if not profile:
|
| 160 |
return (
|
| 161 |
gr.update(value='# ePub Summarization Tool\n\nPlease login to access the tool.'),
|
| 162 |
gr.update(visible=False), # api_key_section
|
| 163 |
gr.update(visible=False), # inp
|
| 164 |
gr.update(visible=False) # clear_key_btn
|
| 165 |
)
|
| 166 |
+
|
| 167 |
+
# Create a mock profile object for compatibility
|
| 168 |
+
class MockProfile:
|
| 169 |
+
def __init__(self, username):
|
| 170 |
+
self.username = username
|
| 171 |
+
self.name = username
|
| 172 |
+
self.email = f"{username}@example.com" # Fallback email
|
| 173 |
+
|
| 174 |
+
mock_profile = MockProfile(profile)
|
| 175 |
+
return self.handle_user_login(mock_profile)
|
| 176 |
|
| 177 |
+
def handle_user_login(self, profile):
|
| 178 |
+
"""Handle user login logic"""
|
| 179 |
if not profile:
|
| 180 |
+
return self.handle_user_logout()
|
| 181 |
|
| 182 |
self.current_user = self._get_user_id(profile)
|
| 183 |
user_name = profile.name if hasattr(profile, 'name') else profile.username
|
|
|
|
| 202 |
gr.update(visible=False) # clear_key_btn
|
| 203 |
)
|
| 204 |
|
| 205 |
+
def handle_user_logout(self):
|
| 206 |
+
"""Handle user logout logic"""
|
| 207 |
self.current_user = None
|
| 208 |
self.api_key = None
|
| 209 |
self.client = None
|
|
|
|
| 346 |
print(f"Error calling Poe API: {e}")
|
| 347 |
return f"Error processing text: {str(e)}"
|
| 348 |
|
| 349 |
+
def process(self, file, request: gr.Request = None):
|
| 350 |
+
# Get user info from request if available
|
| 351 |
+
profile = getattr(request, 'username', None) if request else None
|
| 352 |
+
|
| 353 |
if profile is None:
|
| 354 |
return gr.update(value='⚠️ Please login to access the tool.')
|
| 355 |
|