Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the model
|
| 5 |
+
pipe = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 6 |
+
|
| 7 |
+
def convert_to_json(text):
|
| 8 |
+
prompt = f"Convert this to JSON: {text}"
|
| 9 |
+
output = pipe(prompt, max_new_tokens=200)[0]["generated_text"]
|
| 10 |
+
return output
|
| 11 |
+
|
| 12 |
+
gr.Interface(
|
| 13 |
+
fn=convert_to_json,
|
| 14 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter something like: I spent 2500 on a medical check-up today"),
|
| 15 |
+
outputs=gr.Textbox(label="Generated JSON"),
|
| 16 |
+
title="Natural Language to JSON Converter",
|
| 17 |
+
description="Powered by flan-t5-base"
|
| 18 |
+
).launch()
|