Spaces:
Sleeping
Sleeping
File size: 1,264 Bytes
70845c6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load the model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("Hate-speech-CNERG/urdu-codemixed-abusive-MuRIL")
model = AutoModelForSequenceClassification.from_pretrained("Hate-speech-CNERG/urdu-codemixed-abusive-MuRIL")
# Define labels in Urdu
labels = {0: "نارمل (معمول)", 1: "گالی گلوچ (بدتمیزی)"}
# App title and description
st.title("اردو متن کا تجزیہ کریں")
st.write("یہ ایپ آپ کے فراہم کردہ اردو متن کی نوعیت (نارمل یا گالی گلوچ) کو پہچانتی ہے۔")
# User input
user_input = st.text_area("اردو متن درج کریں:")
if st.button("تجزیہ کریں"):
if user_input.strip():
# Tokenize and classify the input text
inputs = tokenizer(user_input, return_tensors="pt", truncation=True, padding=True)
outputs = model(**inputs)
logits = outputs.logits
predicted_class = torch.argmax(logits, dim=1).item()
# Display the result
st.write(f"متن کی نوعیت: **{labels[predicted_class]}**")
else:
st.warning("براہ کرم متن درج کریں!")
|