app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,36 @@
|
|
1 |
import torch
|
|
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
)
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
27 |
|
28 |
-
|
29 |
-
print("Number of students:", new_students)
|
30 |
-
print("Temperature:", new_temperature)
|
31 |
-
print("Predicted label for number of rooms:", predicted_rooms)
|
|
|
1 |
import torch
|
2 |
+
import gradio as gr
|
3 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
|
5 |
+
def predict_rooms(new_students, new_temperature):
|
6 |
+
# Load the model and tokenizer
|
7 |
+
model_name = "AI" # Replace with the name or path of the model you want to use
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
10 |
|
11 |
+
# Convert the input to tokens
|
12 |
+
inputs = tokenizer.encode_plus(
|
13 |
+
"Number of students: {}, Temperature: {}".format(new_students, new_temperature),
|
14 |
+
padding="max_length",
|
15 |
+
truncation=True,
|
16 |
+
max_length=64,
|
17 |
+
return_tensors="pt"
|
18 |
+
)
|
19 |
|
20 |
+
# Make the prediction
|
21 |
+
with torch.no_grad():
|
22 |
+
outputs = model(**inputs)
|
23 |
+
logits = outputs.logits
|
24 |
+
predicted_rooms = torch.argmax(logits, dim=1).item()
|
25 |
+
|
26 |
+
return predicted_rooms
|
|
|
27 |
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=predict_rooms,
|
30 |
+
inputs=["number", "number"],
|
31 |
+
outputs="number",
|
32 |
+
title="Room Prediction",
|
33 |
+
description="Predict the number of rooms based on the number of students and temperature."
|
34 |
+
)
|
35 |
|
36 |
+
iface.launch()
|
|
|
|
|
|