Spaces:
Paused
Paused
allowing HTML in live preview and adding ReaderLM-2 with JSON outputs
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ from markdown.extensions.fenced_code import FencedCodeExtension
|
|
5 |
from markdown.extensions.toc import TocExtension
|
6 |
from markdown.extensions.attr_list import AttrListExtension
|
7 |
from markdown.extensions.codehilite import CodeHiliteExtension
|
|
|
8 |
|
9 |
# Function to render markdown to HTML with extensions
|
10 |
def render_markdown(md_text):
|
@@ -19,13 +20,29 @@ def render_markdown(md_text):
|
|
19 |
],
|
20 |
)
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# Creating the Gradio Interface
|
23 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
|
24 |
-
|
25 |
with gr.Tab("Live Preview"):
|
26 |
-
|
27 |
gr.Markdown("# Markdown Suite")
|
28 |
-
|
29 |
with gr.Row():
|
30 |
with gr.Column():
|
31 |
md_input = gr.Textbox(
|
@@ -39,5 +56,33 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
|
|
39 |
|
40 |
md_input.change(render_markdown, inputs=md_input, outputs=md_output)
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
# Launch the app
|
43 |
demo.launch()
|
|
|
5 |
from markdown.extensions.toc import TocExtension
|
6 |
from markdown.extensions.attr_list import AttrListExtension
|
7 |
from markdown.extensions.codehilite import CodeHiliteExtension
|
8 |
+
from transformers import pipeline
|
9 |
|
10 |
# Function to render markdown to HTML with extensions
|
11 |
def render_markdown(md_text):
|
|
|
20 |
],
|
21 |
)
|
22 |
|
23 |
+
# Load the JinaAI ReaderLM-v2 model
|
24 |
+
model_name = "jinaai/ReaderLM-v2"
|
25 |
+
html_converter = pipeline("text-generation", model=model_name)
|
26 |
+
|
27 |
+
# Function to convert HTML to Markdown or JSON
|
28 |
+
def convert_html(html_input, output_format):
|
29 |
+
# Prepare the prompt for the model
|
30 |
+
prompt = f"Convert the following HTML into {output_format}:\n\n{html_input}"
|
31 |
+
|
32 |
+
# Generate the output using the model
|
33 |
+
response = html_converter(prompt, max_length=500, num_return_sequences=1)
|
34 |
+
converted_output = response[0]['generated_text']
|
35 |
+
|
36 |
+
# Extract the relevant part of the output (remove the prompt)
|
37 |
+
converted_output = converted_output.replace(prompt, "").strip()
|
38 |
+
return converted_output
|
39 |
+
|
40 |
# Creating the Gradio Interface
|
41 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme") as demo:
|
42 |
+
|
43 |
with gr.Tab("Live Preview"):
|
|
|
44 |
gr.Markdown("# Markdown Suite")
|
45 |
+
|
46 |
with gr.Row():
|
47 |
with gr.Column():
|
48 |
md_input = gr.Textbox(
|
|
|
56 |
|
57 |
md_input.change(render_markdown, inputs=md_input, outputs=md_output)
|
58 |
|
59 |
+
with gr.Tab("HTML to Markdown/JSON"):
|
60 |
+
gr.Markdown("# HTML to Markdown/JSON Converter")
|
61 |
+
|
62 |
+
with gr.Row():
|
63 |
+
html_input = gr.Textbox(
|
64 |
+
lines=10,
|
65 |
+
placeholder="Paste your raw HTML here...",
|
66 |
+
label="Raw HTML Input"
|
67 |
+
)
|
68 |
+
|
69 |
+
output_format = gr.Radio([
|
70 |
+
"Markdown",
|
71 |
+
"JSON"
|
72 |
+
], label="Output Format", value="Markdown")
|
73 |
+
|
74 |
+
converted_output = gr.Textbox(
|
75 |
+
lines=10,
|
76 |
+
label="Converted Output"
|
77 |
+
)
|
78 |
+
|
79 |
+
# Define interaction
|
80 |
+
convert_button = gr.Button("Convert")
|
81 |
+
convert_button.click(
|
82 |
+
convert_html,
|
83 |
+
inputs=[html_input, output_format],
|
84 |
+
outputs=converted_output
|
85 |
+
)
|
86 |
+
|
87 |
# Launch the app
|
88 |
demo.launch()
|