Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline, AutoConfig
|
6 |
+
model_ckpt = "AbhishekBhavnani/TweetClassification"
|
7 |
+
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
9 |
+
model_ckpt,
|
10 |
+
low_cpu_mem_usage=True # To prevent large memory usage during loading
|
11 |
+
)
|
12 |
+
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
|
14 |
+
|
15 |
+
|
16 |
+
# Use the pipeline for text classification
|
17 |
+
classifier = pipeline(
|
18 |
+
'text-classification',
|
19 |
+
model=model,
|
20 |
+
tokenizer=tokenizer,
|
21 |
+
device=-1 # -1 for CPU, set to GPU index if available (e.g., device=0)
|
22 |
+
)
|
23 |
+
|
24 |
+
st.title("Tweet Classification")
|
25 |
+
|
26 |
+
text = st.text_area("Enter Your Tweet Here")
|
27 |
+
|
28 |
+
if st.button("Predict"):
|
29 |
+
result = classifier(text)
|
30 |
+
st.write(result)
|
31 |
+
|
32 |
+
|