jdmartinev commited on
Commit
c915411
·
verified ·
1 Parent(s): 841d434

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the model and tokenizer from Hugging Face Hub
5
+ tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased')
6
+ model = DistilBertForSequenceClassification.from_pretrained('jdmartinev/imdbreviews_classification_distilbert_v02')
7
+
8
+ # Define the function to perform text classification
9
+ def classify_text(input_text):
10
+ inputs = tokenizer(input_text, return_tensors="pt")
11
+ id2label = {0: "negative", 1: "positive"}
12
+ # Get model predictions
13
+ outputs = model(**inputs)
14
+ pred = np.argmax(outputs)# Print logits
15
+ return id2label[pred]
16
+
17
+
18
+ # Create Gradio interface
19
+ iface = gr.Interface(
20
+ fn=classify_text,
21
+ inputs=gr.Textbox(lines=2, placeholder="Enter text to classify"),
22
+ outputs=gr.Tex(label="Class"),
23
+ title="IMDB Review Classifier",
24
+ description="Classify IMDB reviews using a fine-tuned DistilBERT model with LoRA.",
25
+ )
26
+
27
+ # Launch the app
28
+ iface.launch()