akhaliq HF Staff commited on
Commit
76fe7d1
·
1 Parent(s): 008f64a

Fix import order for ZeroGPU compatibility and add JS stream robustness checks

Browse files
Files changed (2) hide show
  1. app.py +11 -9
  2. index.html +4 -0
app.py CHANGED
@@ -1,5 +1,16 @@
1
  import os
2
  import time
 
 
 
 
 
 
 
 
 
 
 
3
  import torch
4
  from typing import Generator
5
  from fastapi.responses import HTMLResponse
@@ -11,15 +22,6 @@ app = Server()
11
  # Define HTML path
12
  HTML_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "index.html")
13
 
14
- # Check if spaces library is available (for Hugging Face Spaces ZeroGPU)
15
- try:
16
- import spaces
17
- has_spaces = True
18
- print("Hugging Face Spaces library loaded successfully.")
19
- except ImportError:
20
- has_spaces = False
21
- print("Hugging Face Spaces library not found. Running in standard environment.")
22
-
23
  # Set device
24
  device = "cuda" if torch.cuda.is_available() else "cpu"
25
  print(f"System detected device: {device}")
 
1
  import os
2
  import time
3
+
4
+ # Check if spaces library is available (for Hugging Face Spaces ZeroGPU)
5
+ # Importing spaces BEFORE torch is a strict ZeroGPU requirement
6
+ try:
7
+ import spaces
8
+ has_spaces = True
9
+ print("Hugging Face Spaces library loaded successfully.")
10
+ except ImportError:
11
+ has_spaces = False
12
+ print("Hugging Face Spaces library not found. Running in standard environment.")
13
+
14
  import torch
15
  from typing import Generator
16
  from fastapi.responses import HTMLResponse
 
22
  # Define HTML path
23
  HTML_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "index.html")
24
 
 
 
 
 
 
 
 
 
 
25
  # Set device
26
  device = "cuda" if torch.cuda.is_available() else "cpu"
27
  print(f"System detected device: {device}")
index.html CHANGED
@@ -1169,6 +1169,10 @@
1169
  let isThinking = false;
1170
  let hasThoughtCompleted = false;
1171
 
 
 
 
 
1172
  if (text.includes("<think>")) {
1173
  const startIndex = text.indexOf("<think>") + 7;
1174
  if (text.includes("</think>")) {
 
1169
  let isThinking = false;
1170
  let hasThoughtCompleted = false;
1171
 
1172
+ if (!text || typeof text !== "string") {
1173
+ return { thinkingText, responseText, isThinking, hasThoughtCompleted };
1174
+ }
1175
+
1176
  if (text.includes("<think>")) {
1177
  const startIndex = text.indexOf("<think>") + 7;
1178
  if (text.includes("</think>")) {