sachit3071 commited on
Commit
533e3ac
Β·
1 Parent(s): 5111b1e

app.py added

Browse files
Files changed (4) hide show
  1. .gitignore +2 -0
  2. README.md +8 -1
  3. app.py +38 -0
  4. requirements.txt +7 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ *.venv
2
+ .venv
README.md CHANGED
@@ -1 +1,8 @@
1
- # sentiment-analysis
 
 
 
 
 
 
 
 
1
+ title: Text To Emotion Classifier
2
+ emoji: πŸ“š
3
+ colorFrom: purple
4
+ colorTo: blue
5
+ sdk: gradio
6
+ sdk_version: 3.45.1
7
+ app_file: app.py
8
+ pinned: false
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import text_hammer as th
4
+ from transformers import DistilBertTokenizer, TFDistilBertForSequenceClassification
5
+
6
+ tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased")
7
+ model = TFDistilBertForSequenceClassification.from_pretrained("Elegbede/Distilbert_FInetuned_For_Text_Classification")
8
+ # Define a function to make predictions
9
+ def predict(texts):
10
+ # Tokenize and preprocess the new text
11
+ new_encodings = tokenizer(texts, truncation=True, padding=True, max_length=70, return_tensors='tf')
12
+ new_predictions = model(new_encodings)
13
+ # Make predictions
14
+ new_predictions = model(new_encodings)
15
+ new_labels_pred = tf.argmax(new_predictions.logits, axis=1)
16
+ new_labels_pred = new_labels_pred.numpy()[0]
17
+
18
+ labels_list = ["Sadness 😭", "Joy πŸ˜‚", "Love 😍", "Anger 😠", "Fear 😨", "Surprise 😲"]
19
+ emotion = labels_list[new_labels_pred]
20
+ return emotion
21
+
22
+ # Create a Gradio interface
23
+ iface = gr.Interface(
24
+ fn=predict,
25
+ inputs="text",
26
+ outputs=gr.outputs.Label(num_top_classes = 6), # Corrected output type
27
+ examples=[["Tears welled up in her eyes as she gazed at the old family photo."],
28
+ ["Laughter filled the room as they reminisced about their adventures."],
29
+ ["A handwritten note awaited her on the kitchen table, a reminder of his affection."],
30
+ ["Harsh words were exchanged in the heated argument."],
31
+ ["The eerie silence of the abandoned building sent shivers down her spine."],
32
+ ["She opened the box to find a rare antique hidden inside, a total shock."]
33
+ ],
34
+ title="Emotion Classification",
35
+ description="Predict the emotion associated with a text using my fine-tuned DistilBERT model."
36
+ )
37
+ # Launch the interfac
38
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio >= 3.45.1
2
+ tensorflow >= 2.13.0
3
+ text_hammer >= 0.1.5
4
+ transformers >= 4.33.3
5
+ spacy == 3.6.1
6
+ scikit-learn >= 1.2.2
7
+ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.6.0/en_core_web_sm-3.6.0.tar.gz