Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,59 @@
|
|
1 |
import gradio as gr
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
with gr.Blocks() as demo:
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
if __name__ == "__main__":
|
8 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
from utils.state import State
|
4 |
+
from utils.process_input import get_response
|
5 |
+
from utils.examples import examples
|
6 |
+
|
7 |
+
|
8 |
+
def clear_fields():
|
9 |
+
app_state.clear_all()
|
10 |
+
return None, None, None
|
11 |
+
|
12 |
+
|
13 |
+
def generate_response(instructions, input_mail):
|
14 |
+
try:
|
15 |
+
model = app_state.model
|
16 |
+
response = get_response(
|
17 |
+
model=model, instructions=instructions, input_texts=input_mail
|
18 |
+
)
|
19 |
+
|
20 |
+
return response
|
21 |
+
except Exception as e:
|
22 |
+
gr.Error(e)
|
23 |
+
|
24 |
+
|
25 |
with gr.Blocks() as demo:
|
26 |
+
gr.Markdown("# Phi3 Mini 4k Model Fine-tuned")
|
27 |
+
gr.Markdown(
|
28 |
+
"**NOTE**: Please note that the response generated by the model might not be accurate. Always verify results."
|
29 |
+
)
|
30 |
+
with gr.Row(equal_height=True):
|
31 |
+
with gr.Column():
|
32 |
+
instructions = gr.TextArea(label="System Instructions", max_lines=2)
|
33 |
+
input_mail = gr.TextArea(label="Input Email", max_lines=6)
|
34 |
+
with gr.Row():
|
35 |
+
submit_button = gr.Button("Submit", variant="primary")
|
36 |
+
clear_button = gr.Button("Clear")
|
37 |
+
|
38 |
+
with gr.Column():
|
39 |
+
with gr.Row():
|
40 |
+
extracted_fields = gr.TextArea(label="Extracted Fields")
|
41 |
+
|
42 |
+
gr.Examples(examples=examples, inputs=[instructions, input_mail])
|
43 |
+
|
44 |
+
clear_button.click(
|
45 |
+
fn=clear_fields,
|
46 |
+
outputs=[instructions, input_mail, extracted_fields],
|
47 |
+
)
|
48 |
+
submit_button.click(
|
49 |
+
fn=generate_response,
|
50 |
+
inputs=[instructions, input_mail],
|
51 |
+
outputs=[extracted_fields],
|
52 |
+
)
|
53 |
|
54 |
if __name__ == "__main__":
|
55 |
+
try:
|
56 |
+
app_state = State()
|
57 |
+
demo.launch()
|
58 |
+
except Exception as e:
|
59 |
+
gr.Error(e)
|