durrani commited on
Commit
34d050c
·
1 Parent(s): a448ea8
Files changed (1) hide show
  1. app.py +29 -24
app.py CHANGED
@@ -1,31 +1,36 @@
1
  import torch
 
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
 
4
- # Load the model and tokenizer
5
- model_name = "AI" # Replace with the name or path of the model you want to use
6
- tokenizer = AutoTokenizer.from_pretrained("AI")
7
- model = AutoModelForSequenceClassification.from_pretrained("AI")
 
8
 
9
- # Values for the new scenario
10
- new_students = int(input("Enter the number of students in the new scenario: "))
11
- new_temperature = int(input("Enter the temperature in the new scenario: "))
 
 
 
 
 
12
 
13
- # Convert the input to tokens
14
- inputs = tokenizer.encode_plus(
15
- "Number of students: {}, Temperature: {}".format(new_students, new_temperature),
16
- padding="max_length",
17
- truncation=True,
18
- max_length=64,
19
- return_tensors="pt"
20
- )
21
 
22
- # Make the prediction
23
- with torch.no_grad():
24
- outputs = model(**inputs)
25
- logits = outputs.logits
26
- predicted_rooms = torch.argmax(logits, dim=1).item()
 
 
27
 
28
- # Print the results
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()