CoolFace
Apppublic

ellenhp/query2osm

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py36 linesDownload Raw Back to root
1from gradio.components import Component2import torch3from hydra import Hydra4from transformers import AutoTokenizer5import gradio as gr6from hydra import Hydra7import os8from typing import Any, Optional9 10model_name = "ellenhp/query2osm-bert-v1"11tokenizer = AutoTokenizer.from_pretrained(model_name, padding=True)12model = Hydra.from_pretrained(model_name).to('cpu')13 14def predict(input_query):15    with torch.no_grad():16        print(input_query)17        input_text = input_query.strip().lower()18        inputs = tokenizer(input_text, return_tensors="pt")19        outputs = model.forward(inputs.input_ids)20        return {classification[0]: classification[1] for classification in outputs.classifications[0]}21 22 23textbox = gr.Textbox(label="Query",24                     placeholder="Quick bite to eat near me")25label = gr.Label(label="Result", num_top_classes=5)26 27gradio_app = gr.Interface(28    predict,29    inputs=[textbox],30    outputs=[label],31    title="Query Classification",32)33 34if __name__ == "__main__":35    gradio_app.launch()36