willco-afk commited on
Commit
1b38594
·
1 Parent(s): b6103c5

Add model and Gradio app

Browse files
Files changed (3) hide show
  1. app.py +22 -0
  2. requirements.txt +3 -0
  3. requirements.txt.txt +3 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+ import torch
4
+
5
+ # Load pre-trained model and tokenizer
6
+ model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased", num_labels=3)
7
+ tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
8
+
9
+ # Define a function to make predictions using the model
10
+ def predict(text):
11
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
12
+ with torch.no_grad():
13
+ outputs = model(**inputs)
14
+ logits = outputs.logits
15
+ predicted_class = torch.argmax(logits, dim=-1).item()
16
+ return predicted_class
17
+
18
+ # Create Gradio interface
19
+ iface = gr.Interface(fn=predict, inputs="text", outputs="text", live=True)
20
+
21
+ # Launch the Gradio app
22
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ git add app.py requirements.txt
2
+ git commit -m "Add model and Gradio app"
3
+ git push
requirements.txt.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ git add app.py requirements.txt
2
+ git commit -m "Add model and Gradio app"
3
+ git push