Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,12 +2,11 @@ import torch
|
|
| 2 |
from transformers import BertTokenizer, BertForSequenceClassification
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
model = BertForSequenceClassification.from_pretrained("
|
| 7 |
-
tokenizer = BertTokenizer.from_pretrained("
|
| 8 |
|
| 9 |
model.eval()
|
| 10 |
-
|
| 11 |
label_map = {0: "statement", 1: "question"}
|
| 12 |
|
| 13 |
def classify_sentence(text):
|
|
@@ -17,7 +16,6 @@ def classify_sentence(text):
|
|
| 17 |
predicted_class = torch.argmax(outputs.logits, dim=1).item()
|
| 18 |
return label_map[predicted_class]
|
| 19 |
|
| 20 |
-
# Gradio Interface
|
| 21 |
interface = gr.Interface(
|
| 22 |
fn=classify_sentence,
|
| 23 |
inputs=gr.Textbox(lines=2, placeholder="Enter a sentence..."),
|
|
|
|
| 2 |
from transformers import BertTokenizer, BertForSequenceClassification
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# Load model from local folder
|
| 6 |
+
model = BertForSequenceClassification.from_pretrained(".", trust_remote_code=True)
|
| 7 |
+
tokenizer = BertTokenizer.from_pretrained(".")
|
| 8 |
|
| 9 |
model.eval()
|
|
|
|
| 10 |
label_map = {0: "statement", 1: "question"}
|
| 11 |
|
| 12 |
def classify_sentence(text):
|
|
|
|
| 16 |
predicted_class = torch.argmax(outputs.logits, dim=1).item()
|
| 17 |
return label_map[predicted_class]
|
| 18 |
|
|
|
|
| 19 |
interface = gr.Interface(
|
| 20 |
fn=classify_sentence,
|
| 21 |
inputs=gr.Textbox(lines=2, placeholder="Enter a sentence..."),
|