| from huggingface_hub import hf_hub_download | |
| import fasttext | |
| import gradio as gr | |
| # ๋ชจ๋ธ ๋ค์ด๋ก๋ | |
| model_path = hf_hub_download(repo_id="cis-lmu/glotlid", filename="model.bin") | |
| # ๋ชจ๋ธ ๋ก๋ | |
| model = fasttext.load_model(model_path) | |
| # ์์ธก ํจ์ | |
| def predict_language(text): | |
| predictions = model.predict(text) | |
| return { | |
| "Predicted language": predictions[0][0], | |
| "Confidence score": predictions[1][0] | |
| } | |
| # Gradio ์ธํฐํ์ด์ค | |
| interface = gr.Interface( | |
| fn=predict_language, | |
| inputs=gr.Textbox(label="Input Text"), | |
| outputs="json", | |
| title="Language Predictor" | |
| ) | |
| interface.launch() | |