Thebull commited on
Commit
af4daa5
1 Parent(s): d256a23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -1,12 +1,23 @@
1
- from transformers import AutoModelForCausalLM, AutoTokenizer
 
2
 
3
- model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
4
- tokenizer = AutoTokenizer.from_pretrained(model_id)
 
5
 
6
- model = AutoModelForCausalLM.from_pretrained(model_id)
 
 
 
 
 
 
 
 
7
 
8
- text = "Hello my name is"
9
- inputs = tokenizer(text, return_tensors="pt")
10
 
11
- outputs = model.generate(**inputs, max_new_tokens=20)
12
- print(tokenizer.decode(outputs[0], skip_special_tokens=True))
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
 
4
+ # Load pre-trained tokenizer and model
5
+ tokenizer = AutoTokenizer.from_pretrained('distilbert-base-uncased')
6
+ model = AutoModelForSequenceClassification.from_pretrained('distilbert-base-uncased', num_labels=2)
7
 
8
+ def predict_sentiment(input_text):
9
+ # Tokenization
10
+ inputs = tokenizer(input_text, return_tensors='pt')
11
+
12
+ # Prediction
13
+ outputs = model(**inputs)
14
+ probabilities = outputs[0][0].detach().numpy()
15
+ labels = ['Negative', 'Positive']
16
+ predicted_label = labels[probabilities.argmax()]
17
 
18
+ return {"Text": input_text, "Sentiment": predicted_label}
 
19
 
20
+ iface = gr.Interface(predict_sentiment, input_type="text", output_types=["text"],
21
+ input_label="Enter Text", output_label="Predicted Sentiment")
22
+
23
+ iface.launch()