app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,20 @@
|
|
1 |
-
import
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
"Number of students: {}, Temperature: {}".format(new_students, new_temperature),
|
13 |
-
padding="max_length",
|
14 |
-
truncation=True,
|
15 |
-
max_length=64,
|
16 |
-
return_tensors="pt"
|
17 |
-
)
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
outputs = model(**inputs)
|
22 |
-
logits = outputs.logits
|
23 |
-
predicted_rooms = torch.argmax(logits, dim=1).item()
|
24 |
|
25 |
-
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
iface = gr.Interface(
|
31 |
-
fn=[predict_rooms, greet],
|
32 |
-
inputs=[["number", "number"], "text"],
|
33 |
-
outputs=["number", "text"],
|
34 |
-
title="Room Prediction",
|
35 |
-
description="Predict the number of rooms based on the number of students and temperature, and greet the user."
|
36 |
-
)
|
37 |
-
|
38 |
-
iface.launch()
|
|
|
1 |
+
import torch
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
|
4 |
+
# Load tokenizer and model
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased", num_labels=1)
|
|
|
|
|
7 |
|
8 |
+
# Input text
|
9 |
+
text = "I want to book a flight from New York to London on July 1st."
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# Tokenize input text
|
12 |
+
inputs = tokenizer(text, padding=True, truncation=True, return_tensors="pt")
|
|
|
|
|
|
|
13 |
|
14 |
+
# Predict flight ticket
|
15 |
+
with torch.no_grad():
|
16 |
+
logits = model(**inputs).logits
|
17 |
+
prediction = torch.sigmoid(logits).item()
|
18 |
|
19 |
+
# Display prediction
|
20 |
+
print("Flight ticket prediction:", prediction)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|