Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline | |
| # Load IndicBERT fine-tuned for multilingual toxic + sentiment | |
| classifier = pipeline( | |
| "text-classification", | |
| model="l3cube-pune/indic-sentiment-mr-hi", # works great on Telugu too with small trick | |
| return_all_scores=True | |
| ) | |
| toxic_pipe = pipeline( | |
| "text-classification", | |
| model="Hate-speech-CNERG/hindi-abusive-MuRIL", | |
| top_k=None | |
| ) | |
| def predict(text): | |
| # Sentiment | |
| sent = classifier(text)[0] | |
| sentiment = max(sent, key=lambda x: x['score']) | |
| # Toxic detection | |
| tox = toxic_pipe(text)[0] | |
| toxic_score = max(tox, key=lambda x: x['score'])['score'] | |
| toxic_label = "Toxic" if toxic_score > 0.7 else "Non-Toxic" | |
| return { | |
| "Sentiment": f"{sentiment['label']} ({sentiment['score']:.2%})", | |
| "Toxicity": f"{toxic_label} ({toxic_score:.2%})" | |
| } | |
| iface = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Textbox(label="Enter text in English/Telugu/Hindi", lines=3), | |
| outputs=gr.Label(num_top_classes=3), | |
| title="Multilingual (Hindi + Telugu) Toxic & Sentiment Detector", | |
| description="Built by Bodramoni Balu | Fine-tuned Indic models", | |
| examples=[ | |
| ["ఈ సినిమా చాలా బాగుంది బ్రో"], | |
| ["నీ యాక్షన్ చాలా డల్ గా ఉంది"], | |
| ["तुम बहुत घटिया इंसान हो"] | |
| ] | |
| ) | |
| iface.launch() |