Felguk/ReaderLM-v2
2
1import gradio as gr2from transformers import pipeline3 4# Load the JinaAI ReaderLM-v2 model5model_name = "jinaai/ReaderLM-v2"6html_converter = pipeline("text-generation", model=model_name)7 8# Function to convert HTML to Markdown or JSON9def convert_html(html_input, output_format):10 # Prepare the prompt for the model11 prompt = f"Convert the following HTML into {output_format}:\n\n{html_input}"12 13 # Generate the output using the model14 response = html_converter(prompt, max_length=500, num_return_sequences=1)15 converted_output = response[0]['generated_text']16 17 # Extract the relevant part of the output (remove the prompt)18 converted_output = converted_output.replace(prompt, "").strip()19 return converted_output20 21# Gradio Interface with NoCrypt/miku theme22interface = gr.Interface(23 fn=convert_html,24 inputs=[25 gr.Textbox(lines=10, placeholder="Paste your raw HTML here...", label="Raw HTML Input"),26 gr.Radio(["Markdown", "JSON"], label="Output Format", value="Markdown")27 ],28 outputs=gr.Textbox(lines=10, label="Converted Output"),29 title="HTML to Markdown/JSON Converter",30 description="Convert raw HTML into beautifully formatted Markdown or JSON using JinaAI ReaderLM-v2.",31 theme="NoCrypt/miku", # Apply the NoCrypt/miku theme32 examples=[33 ["<h1>Hello World</h1><p>This is a <strong>test</strong>.</p>", "Markdown"],34 ["<ul><li>Item 1</li><li>Item 2</li></ul>", "JSON"]35 ]36)37 38# Launch the interface39interface.launch()