File size: 1,002 Bytes
e9d731a 25ef427 e9d731a 7453a11 e9d731a 25ef427 e9d731a 25ef427 e9d731a 25ef427 e9d731a 25ef427 |
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 32 |
from transformers import AutoModel
import gradio as gr
import fasttext
import torch
from huggingface_hub import hf_hub_download
repo_id = "tevykuch/zeroshot-reptile"
filename = "metalearn_wordy.bin"
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
fasttext_model = fasttext.load_model(model_path)
model = AutoModel.from_pretrained(repo_id, force_download=True)
def predict(input_text):
words = input_text.split()
embeddings = torch.tensor([fasttext_model.get_word_vector(word) for word in words])
avg_embedding = embeddings.mean(dim=0).unsqueeze(0)
with torch.no_grad():
output = model(avg_embedding)
predicted_class = output.argmax(dim=1).item()
return f"Predicted class: {predicted_class}"
iface = gr.Interface(fn=predict,
inputs="text",
outputs="text",
title="My Model Demo",
description="Enter some text to see the model prediction.")
iface.launch() |