Spaces:
Running
on
Zero
Running
on
Zero
Lord-Raven
commited on
Commit
·
e2dc7bd
1
Parent(s):
ac1ebcc
Swapping CPU model.
Browse files- app.py +9 -5
- requirements.txt +3 -3
app.py
CHANGED
|
@@ -23,16 +23,20 @@ app.add_middleware(
|
|
| 23 |
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
| 24 |
if torch.cuda.is_available():
|
| 25 |
print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
def classify(data_string, request: gradio.Request):
|
| 34 |
if request:
|
| 35 |
-
if request.headers["origin"] not in ["https://statosphere-3704059fdd7e.c5v4v4jx6pq5.win", "https://crunchatize-77a78ffcc6a6.c5v4v4jx6pq5.win", "https://crunchatize-2-2b4f5b1479a6.c5v4v4jx6pq5.win", "https://tamabotchi-2dba63df3bf1.c5v4v4jx6pq5.win", "https://ravenok-statosphere-backend.hf.space", "https://lord-raven.github.io"]:
|
| 36 |
return "{}"
|
| 37 |
data = json.loads(data_string)
|
| 38 |
|
|
|
|
| 23 |
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
| 24 |
if torch.cuda.is_available():
|
| 25 |
print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
| 26 |
+
print(f"CUDA version: {torch.version.cuda}")
|
| 27 |
|
| 28 |
+
model_name_cpu = "MoritzLaurer/ModernBERT-large-zeroshot-v2.0"
|
| 29 |
+
tokenizer_name_cpu = "MoritzLaurer/ModernBERT-large-zeroshot-v2.0"
|
| 30 |
|
| 31 |
+
model_name_gpu = "MoritzLaurer/roberta-large-zeroshot-v2.0-c"
|
| 32 |
+
tokenizer_name_gpu = "MoritzLaurer/roberta-large-zeroshot-v2.0-c"
|
| 33 |
+
|
| 34 |
+
classifier_cpu = pipeline(task="zero-shot-classification", model=model_name_cpu, tokenizer=tokenizer_name_cpu, device="cpu", torch_dtype=torch.bfloat16)
|
| 35 |
+
classifier_gpu = pipeline(task="zero-shot-classification", model=model_name_gpu, tokenizer=tokenizer_name_gpu, device="cuda", torch_dtype=torch.bfloat16) if torch.cuda.is_available() else classifier_cpu
|
| 36 |
|
| 37 |
def classify(data_string, request: gradio.Request):
|
| 38 |
if request:
|
| 39 |
+
if request.headers["origin"] not in ["https://statosphere-3704059fdd7e.c5v4v4jx6pq5.win", "https://crunchatize-77a78ffcc6a6.c5v4v4jx6pq5.win", "https://crunchatize-2-2b4f5b1479a6.c5v4v4jx6pq5.win", "https://tamabotchi-2dba63df3bf1.c5v4v4jx6pq5.win", "https://ravenok-statosphere-backend.hf.space", "https://ravenok-test-space.hf.space", "https://lord-raven.github.io"]:
|
| 40 |
return "{}"
|
| 41 |
data = json.loads(data_string)
|
| 42 |
|
requirements.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
torch==2.4.0
|
| 2 |
fastapi==0.88.0
|
| 3 |
-
huggingface_hub==0.
|
| 4 |
json5==0.9.25
|
| 5 |
numpy
|
| 6 |
uvicorn
|
| 7 |
-
optimum[onnxruntime-gpu]==1.
|
| 8 |
-
transformers==4.
|
|
|
|
| 1 |
torch==2.4.0
|
| 2 |
fastapi==0.88.0
|
| 3 |
+
huggingface_hub==0.33.0
|
| 4 |
json5==0.9.25
|
| 5 |
numpy
|
| 6 |
uvicorn
|
| 7 |
+
optimum[onnxruntime-gpu]==1.26.1
|
| 8 |
+
transformers==4.52.4
|