Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import streamlit as st
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
+
import re
|
5 |
+
import torch
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")
|
8 |
+
|
9 |
+
def analyze_text(text):
|
10 |
+
text = re.sub(r"[^\w\s]", "", text)
|
11 |
+
text = text.lower()
|
12 |
+
encoded_text = tokenizer(text, truncation=True, padding=True, return_tensors='pt')
|
13 |
+
|
14 |
+
with torch.no_grad():
|
15 |
+
output = model(**encoded_text)
|
16 |
+
predictions = output.logits.argmax(-1).item()
|
17 |
+
|
18 |
+
if predictions == 0:
|
19 |
+
return "Job Interview Related"
|
20 |
+
else:
|
21 |
+
return "Not Job Interview Related"
|
22 |
+
st.title("Job Interview Message Analyzer")
|
23 |
+
|
24 |
+
uploaded_file = st.file_uploader("Upload CSV file")
|
25 |
+
user_input = st.text_input("Enter text")
|
26 |
+
|
27 |
+
if uploaded_file:
|
28 |
+
data = pd.read_csv(uploaded_file)
|
29 |
+
results = []
|
30 |
+
for message in data["message"]:
|
31 |
+
result = analyze_text(message)
|
32 |
+
results.append(result)
|
33 |
+
data["Job_Interview_Related"] = results
|
34 |
+
st.dataframe(data)
|
35 |
+
elif user_input:
|
36 |
+
result = analyze_text(user_input)
|
37 |
+
st.write(f"Message Classification: {result}")
|
38 |
+
else:
|
39 |
+
st.write("Please upload a CSV file or enter text to analyze.")
|