Spaces:
Sleeping
Sleeping
Download app.py from Kaditya999/sample: direct link, hf CLI and curl.
- Browser
- Download file 976 Bytes
-
https://huggingface.co/spaces/Kaditya999/sample/resolve/main/app.py
- Command line
-
hf download hf://spaces/Kaditya999/sample/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Kaditya999/sample/resolve/main/app.py
976 Bytes
| 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) | |