|
| 1 | +import gradio as gr |
| 2 | +from typing import Callable |
| 3 | + |
| 4 | +example_text = """We introduce Mistral 7B, a 7-billion-parameter language model engineered for |
| 5 | +superior performance and efficiency. Mistral 7B outperforms the best open 13B |
| 6 | +model (Llama 2) across all evaluated benchmarks, and the best released 34B |
| 7 | +model (Llama 1) in reasoning, mathematics, and code generation. Our model |
| 8 | +leverages grouped-query attention (GQA) for faster inference, coupled with sliding |
| 9 | +window attention (SWA) to effectively handle sequences of arbitrary length with a |
| 10 | +reduced inference cost. We also provide a model fine-tuned to follow instructions, |
| 11 | +Mistral 7B - Instruct, that surpasses Llama 2 13B - chat model both on human and |
| 12 | +automated benchmarks. Our models are released under the Apache 2.0 license. |
| 13 | +Code: https://github.com/mistralai/mistral-src |
| 14 | +Webpage: https://mistral.ai/news/announcing-mistral-7b/""" |
| 15 | + |
| 16 | +example_schema = """{ |
| 17 | + "Model": { |
| 18 | + "Name": "", |
| 19 | + "Number of parameters": "", |
| 20 | + "Number of max token": "", |
| 21 | + "Architecture": [] |
| 22 | + }, |
| 23 | + "Usage": { |
| 24 | + "Use case": [], |
| 25 | + "Licence": "" |
| 26 | + } |
| 27 | +}""" |
| 28 | + |
| 29 | + |
| 30 | +def make_demo(fn: Callable): |
| 31 | + with gr.Blocks() as demo: |
| 32 | + gr.Markdown("# Structure Extraction with NuExtract and OpenVINO") |
| 33 | + |
| 34 | + with gr.Row(): |
| 35 | + with gr.Column(): |
| 36 | + text_textbox = gr.Textbox( |
| 37 | + label="Text", |
| 38 | + placeholder="Text from which to extract information", |
| 39 | + lines=5, |
| 40 | + ) |
| 41 | + schema_textbox = gr.Code( |
| 42 | + label="JSON Schema", |
| 43 | + language="json", |
| 44 | + lines=5, |
| 45 | + ) |
| 46 | + with gr.Column(): |
| 47 | + model_output_textbox = gr.Code( |
| 48 | + label="Model Response", |
| 49 | + language="json", |
| 50 | + interactive=False, |
| 51 | + lines=10, |
| 52 | + ) |
| 53 | + with gr.Row(): |
| 54 | + gr.ClearButton(components=[text_textbox, schema_textbox, model_output_textbox]) |
| 55 | + submit_button = gr.Button(value="Submit", variant="primary") |
| 56 | + with gr.Row(): |
| 57 | + gr.Examples(examples=[[example_text, example_schema]], inputs=[text_textbox, schema_textbox]) |
| 58 | + |
| 59 | + submit_button.click( |
| 60 | + fn, |
| 61 | + [text_textbox, schema_textbox], |
| 62 | + [model_output_textbox], |
| 63 | + ) |
| 64 | + return demo |
0 commit comments