jdmartinev commited on
Commit
19c28fa
·
verified ·
1 Parent(s): 851e2d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -19
app.py CHANGED
@@ -1,28 +1,17 @@
1
  import gradio as gr
2
  from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
 
 
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()
 
1
  import gradio as gr
2
  from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
3
+ from huggingface_hub import hf_hub_download
4
+ import numpy as np
5
 
 
6
  tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased')
7
  model = DistilBertForSequenceClassification.from_pretrained('jdmartinev/imdbreviews_classification_distilbert_v02')
8
+ id2label = {0: "negative", 1: "positive"}
9
 
10
+ def classify_text(input_text,id2label):
 
11
  inputs = tokenizer(input_text, return_tensors="pt")
 
 
12
  outputs = model(**inputs)
13
+ pred = np.argmax(outputs)
14
+ return(pred)
 
15
 
16
+ demo = gr.Interface(classify_text, "text", "text")
17
+ demo.launch()