Khoi1234210 commited on
Commit
f1aa7aa
·
verified ·
1 Parent(s): 4b8fdd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -28
app.py CHANGED
@@ -3,31 +3,7 @@ import os
3
  from huggingface_hub import InferenceClient
4
  from datasets import load_dataset
5
  import random
6
- import secrets
7
- # Fix for SessionMiddleware error in HF Spaces
8
- def configure_gradio_session():
9
- """Configure session middleware for Gradio in HF Spaces"""
10
- try:
11
- from starlette.middleware.sessions import SessionMiddleware
12
- import gradio.routes
13
-
14
- # Store original create_app function
15
- if hasattr(gradio.routes, 'App') and hasattr(gradio.routes.App, 'create_app'):
16
- original_create_app = gradio.routes.App.create_app
17
-
18
- def patched_create_app(self, *args, **kwargs):
19
- app = original_create_app(self, *args, **kwargs)
20
- # Add session middleware
21
- app.add_middleware(
22
- SessionMiddleware,
23
- secret_key=os.getenv("HF_SESSION_SECRET", secrets.token_hex(32))
24
- )
25
- return app
26
-
27
- gradio.routes.App.create_app = patched_create_app
28
-
29
- except (ImportError, AttributeError) as e:
30
- print(f"Warning: Could not configure session middleware: {e}")
31
 
32
  # Call the configuration function
33
  configure_gradio_session()
@@ -216,9 +192,6 @@ chatbot = gr.ChatInterface(
216
  )
217
 
218
  # Enhanced interface with additional features
219
- with gr.Blocks() as demo:
220
- with gr.Row():
221
- login_btn = gr.LoginButton() # Manual login button
222
  with gr.Blocks(
223
  title="🧮 Mathetics AI",
224
  theme=gr.themes.Soft(),
 
3
  from huggingface_hub import InferenceClient
4
  from datasets import load_dataset
5
  import random
6
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # Call the configuration function
9
  configure_gradio_session()
 
192
  )
193
 
194
  # Enhanced interface with additional features
 
 
 
195
  with gr.Blocks(
196
  title="🧮 Mathetics AI",
197
  theme=gr.themes.Soft(),