Spaces:
Sleeping
Sleeping
| 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) | |