Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,30 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import spaces
|
|
|
|
| 4 |
import torch
|
| 5 |
|
| 6 |
zero = torch.Tensor([0]).cuda()
|
| 7 |
print(zero.device) # <-- 'cpu' 🤔
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
@spaces.GPU
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
return f"Hello {zero + n} Tensor"
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import spaces
|
| 4 |
+
from transformers import pipeline
|
| 5 |
import torch
|
| 6 |
|
| 7 |
zero = torch.Tensor([0]).cuda()
|
| 8 |
print(zero.device) # <-- 'cpu' 🤔
|
| 9 |
|
| 10 |
+
token = os.getenv("HF_TOKEN")
|
| 11 |
+
# gr.load("models/ICILS/xlm-r-icils-ilo", hf_token=token).launch()
|
| 12 |
+
|
| 13 |
+
# Load the pre-trained model
|
| 14 |
+
classifier = pipeline("text-classification", model="ICILS/xlm-r-icils-ilo", hf_token=token)
|
| 15 |
+
|
| 16 |
+
# Define the prediction function
|
| 17 |
@spaces.GPU
|
| 18 |
+
def classify_text(text):
|
| 19 |
+
return classifier(text)[0]
|
|
|
|
| 20 |
|
| 21 |
+
# Create the Gradio interface
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=classify_text,
|
| 24 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
| 25 |
+
outputs=gr.Text(),
|
| 26 |
+
title="XLM-R ISCO classification with ZeroGPU",
|
| 27 |
+
description="Classify occupations using a pre-trained XLM-R-ISCO model on Hugging Face Spaces with ZeroGPU"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
demo.launch()
|