File size: 689 Bytes
bf278fc
 
 
 
e9dafe3
bf278fc
 
e9dafe3
bf278fc
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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()