Spaces:
Sleeping
Sleeping
File size: 976 Bytes
ec5ddc5 | 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 | import gradio as gr
from transformers import AutoTokenizer, AutoModel
import torch
MODEL_NAME = "google/muril-base-cased"
# load model (this downloads from huggingface model hub automatically)
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModel.from_pretrained(MODEL_NAME)
def analyze_text(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
outputs = model(**inputs)
# CLS token embedding
embeddings = outputs.last_hidden_state[:, 0, :]
return str(embeddings.tolist())
iface = gr.Interface(
fn=analyze_text,
inputs=gr.Textbox(lines=4, label="Enter Text (Hindi, English, Tamil etc)"),
outputs=gr.Textbox(label="MuRIL Semantic Embedding"),
title="Indian Language Political Text Analyzer (MuRIL)",
description="This app uses Google's MuRIL model to understand Indian language political text."
)
iface.launch(server_name="0.0.0.0", server_port=7860)
|