File size: 1,663 Bytes
3abf916
 
e0c9026
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3abf916
e0c9026
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3abf916
 
e0c9026
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import gradio as gr

from utils.state import State
from utils.process_input import get_response
from utils.examples import examples


def clear_fields():
    app_state.clear_all()
    return None, None, None


def generate_response(instructions, input_mail):
    try:
        model = app_state.model
        response = get_response(
            model=model, instructions=instructions, input_texts=input_mail
        )

        return response
    except Exception as e:
        gr.Error(e)


with gr.Blocks() as demo:
    gr.Markdown("# Phi3 Mini 4k Model Fine-tuned")
    gr.Markdown(
        "**NOTE**: Please note that the response generated by the model might not be accurate. Always verify results."
    )
    with gr.Row(equal_height=True):
        with gr.Column():
            instructions = gr.TextArea(label="System Instructions", max_lines=2)
            input_mail = gr.TextArea(label="Input Email", max_lines=6)
            with gr.Row():
                submit_button = gr.Button("Submit", variant="primary")
                clear_button = gr.Button("Clear")

        with gr.Column():
            with gr.Row():
                extracted_fields = gr.TextArea(label="Extracted Fields")

    gr.Examples(examples=examples, inputs=[instructions, input_mail])

    clear_button.click(
        fn=clear_fields,
        outputs=[instructions, input_mail, extracted_fields],
    )
    submit_button.click(
        fn=generate_response,
        inputs=[instructions, input_mail],
        outputs=[extracted_fields],
    )

if __name__ == "__main__":
    try:
        app_state = State()
        demo.launch()
    except Exception as e:
        gr.Error(e)