CWM-Coder724 commited on
Commit
d75262b
·
1 Parent(s): 6153e75

Configure ZeroGPU entrypoint with Gradio and clean dependencies

Browse files
Files changed (3) hide show
  1. README.md +0 -1
  2. app.py +31 -14
  3. requirements.txt +0 -4
README.md CHANGED
@@ -4,7 +4,6 @@ emoji: ⚡
4
  colorFrom: indigo
5
  colorTo: blue
6
  sdk: gradio
7
- sdk_version: 5.0.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
4
  colorFrom: indigo
5
  colorTo: blue
6
  sdk: gradio
 
7
  app_file: app.py
8
  pinned: false
9
  ---
app.py CHANGED
@@ -1,25 +1,42 @@
 
 
 
 
 
 
 
 
 
1
  import os
2
  import sys
 
3
 
4
- # Add backend directory to Python module search path
5
  backend_dir = os.path.join(os.path.dirname(__file__), "backend")
6
  if backend_dir not in sys.path:
7
  sys.path.insert(0, backend_dir)
8
 
9
- # Hugging Face ZeroGPU requirement: at least one @spaces.GPU function during startup
10
- try:
11
- import spaces
12
- @spaces.GPU(duration=120)
13
- def _zerogpu_init():
14
- """Satisfies Hugging Face ZeroGPU startup check."""
15
- print("[ZeroGPU] Initialized successfully.")
16
- return True
17
- _zerogpu_init()
18
- except Exception as e:
19
- print("[ZeroGPU] Notice:", e)
20
 
21
- from main import app
22
- import uvicorn
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  if __name__ == "__main__":
25
  port = int(os.environ.get("PORT", 7860))
 
1
+ # Hugging Face ZeroGPU requirement: 'spaces' MUST be imported before any ML libraries
2
+ try:
3
+ import spaces
4
+ import gradio as gr
5
+ HAS_ZEROGPU = True
6
+ except Exception as e:
7
+ print("[ZeroGPU] Notice:", e)
8
+ HAS_ZEROGPU = False
9
+
10
  import os
11
  import sys
12
+ import uvicorn
13
 
14
+ # Add backend directory to Python path
15
  backend_dir = os.path.join(os.path.dirname(__file__), "backend")
16
  if backend_dir not in sys.path:
17
  sys.path.insert(0, backend_dir)
18
 
19
+ from main import app as fastapi_app
 
 
 
 
 
 
 
 
 
 
20
 
21
+ if HAS_ZEROGPU:
22
+ @spaces.GPU
23
+ def predict(status: str = "Ready") -> str:
24
+ """ZeroGPU function satisfying Hugging Face startup requirement."""
25
+ return "Clash of Minds AI Judge Active"
26
+
27
+ demo = gr.Interface(
28
+ fn=predict,
29
+ inputs=gr.Textbox(label="Status", value="Ready"),
30
+ outputs=gr.Textbox(label="Response"),
31
+ title="Clash of Minds — AI Debate Judge",
32
+ )
33
+
34
+ # Mount Gradio interface under /gradio; full custom debate UI stays at "/"
35
+ app = gr.mount_gradio_app(fastapi_app, demo, path="/gradio")
36
+ print("[HuggingFace] ZeroGPU & Gradio interface mounted at /gradio successfully.")
37
+ else:
38
+ demo = None
39
+ app = fastapi_app
40
 
41
  if __name__ == "__main__":
42
  port = int(os.environ.get("PORT", 7860))
requirements.txt CHANGED
@@ -7,7 +7,6 @@ python-multipart
7
  # NLP pipelines
8
  sentence-transformers
9
  transformers
10
- torch
11
  scipy
12
  scikit-learn
13
  numpy
@@ -28,6 +27,3 @@ aiosqlite
28
 
29
  # Utilities
30
  python-dotenv
31
- gradio
32
-
33
- spaces
 
7
  # NLP pipelines
8
  sentence-transformers
9
  transformers
 
10
  scipy
11
  scikit-learn
12
  numpy
 
27
 
28
  # Utilities
29
  python-dotenv