Spaces:
Running
Running
import gradio as gr | |
from transformers import pipeline | |
# Load the model | |
pipe = pipeline("text2text-generation", model="declare-lab/flan-alpaca-base") | |
def convert_to_json(text): | |
prompt = f"Convert the following sentence into a JSON object with keys: userId, type, category, amount, date, note: {text}" | |
output = pipe(prompt, max_new_tokens=200)[0]["generated_text"] | |
return output | |
gr.Interface( | |
fn=convert_to_json, | |
inputs=gr.Textbox(lines=2, placeholder="Enter something like: I spent 2500 on a medical check-up today"), | |
outputs=gr.Textbox(label="Generated JSON"), | |
title="Natural Language to JSON Converter", | |
description="Powered by flan-t5-base" | |
).launch() | |