Spaces:
Running
on
Zero
Running
on
Zero
Martín Santillán Cooper
commited on
Commit
•
20a9c66
1
Parent(s):
2cecaad
Bring back yes/no bold text
Browse files- src/app.py +9 -4
- src/model.py +14 -15
- src/styles.css +22 -19
src/app.py
CHANGED
@@ -51,8 +51,8 @@ def on_submit(criteria, context, user_message, assistant_message, state):
|
|
51 |
logger.debug(f"Starting evaluation for subcatelog {state['selected_sub_catalog']} and criteria name {state['selected_criteria_name']}")
|
52 |
result_label = generate_text(prompt)['assessment'] # Yes or No
|
53 |
|
54 |
-
|
55 |
-
html_str = f"{get_result_description(state['selected_sub_catalog'], state['selected_criteria_name'])} {result_label}"
|
56 |
return gr.update(value=html_str)
|
57 |
|
58 |
def on_show_prompt_click(criteria, context, user_message, assistant_message, state):
|
@@ -159,15 +159,20 @@ with gr.Blocks(
|
|
159 |
icon=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'send-white.png'),
|
160 |
elem_classes='submit-button')
|
161 |
|
162 |
-
result_text = gr.
|
|
|
163 |
label='Result',
|
164 |
-
elem_classes=['result-
|
|
|
165 |
visible=False,
|
166 |
value='')
|
167 |
|
168 |
with Modal(visible=False, elem_classes='modal') as modal:
|
169 |
prompt = gr.Markdown('')
|
170 |
|
|
|
|
|
|
|
171 |
show_propt_button.click(
|
172 |
on_show_prompt_click,
|
173 |
inputs=[criteria, context, user_message, assistant_message, state],
|
|
|
51 |
logger.debug(f"Starting evaluation for subcatelog {state['selected_sub_catalog']} and criteria name {state['selected_criteria_name']}")
|
52 |
result_label = generate_text(prompt)['assessment'] # Yes or No
|
53 |
|
54 |
+
html_str = f"<p>{get_result_description(state['selected_sub_catalog'], state['selected_criteria_name'])} <strong>{result_label}</strong></p>"
|
55 |
+
# html_str = f"{get_result_description(state['selected_sub_catalog'], state['selected_criteria_name'])} {result_label}"
|
56 |
return gr.update(value=html_str)
|
57 |
|
58 |
def on_show_prompt_click(criteria, context, user_message, assistant_message, state):
|
|
|
159 |
icon=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'send-white.png'),
|
160 |
elem_classes='submit-button')
|
161 |
|
162 |
+
# result_text = gr.HTML(label='Result', elem_classes=['result-text', 'read-only', 'input-box'], visible=False, value='')
|
163 |
+
result_text = gr.HTML(
|
164 |
label='Result',
|
165 |
+
elem_classes=['result-root'],
|
166 |
+
show_label=True,
|
167 |
visible=False,
|
168 |
value='')
|
169 |
|
170 |
with Modal(visible=False, elem_classes='modal') as modal:
|
171 |
prompt = gr.Markdown('')
|
172 |
|
173 |
+
|
174 |
+
### events
|
175 |
+
|
176 |
show_propt_button.click(
|
177 |
on_show_prompt_click,
|
178 |
inputs=[criteria, context, user_message, assistant_message, state],
|
src/model.py
CHANGED
@@ -60,23 +60,22 @@ def generate_text(prompt):
|
|
60 |
logger.debug('Returning mocked model result.')
|
61 |
sleep(1)
|
62 |
return {'assessment': 'Yes', 'certainty': 0.97}
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
tokenized_chat = tokenizer.apply_chat_template([prompt], tokenize=False, add_generation_prompt=True)
|
67 |
|
68 |
-
|
69 |
-
|
70 |
|
71 |
-
|
72 |
|
73 |
-
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
|
82 |
-
|
|
|
60 |
logger.debug('Returning mocked model result.')
|
61 |
sleep(1)
|
62 |
return {'assessment': 'Yes', 'certainty': 0.97}
|
63 |
+
start = time()
|
64 |
+
|
65 |
+
tokenized_chat = tokenizer.apply_chat_template([prompt], tokenize=False, add_generation_prompt=True)
|
|
|
66 |
|
67 |
+
with torch.no_grad():
|
68 |
+
output = model.generate(tokenized_chat, sampling_params, use_tqdm=False)
|
69 |
|
70 |
+
# predicted_label = output[0].outputs[0].text.strip()
|
71 |
|
72 |
+
label, prob_of_risk = parse_output(output[0])
|
73 |
|
74 |
+
logger.debug(f'Model generated label: \n{label}')
|
75 |
+
logger.debug(f'Model prob_of_risk: \n{prob_of_risk}')
|
76 |
+
|
77 |
+
end = time()
|
78 |
+
total = end - start
|
79 |
+
logger.debug(f'The evaluation took {total} secs')
|
80 |
|
81 |
+
return {'assessment': label, 'certainty': prob_of_risk}
|
src/styles.css
CHANGED
@@ -73,40 +73,43 @@
|
|
73 |
}
|
74 |
|
75 |
.read-only label textarea,input {
|
76 |
-
|
77 |
/* border: none;
|
78 |
box-shadow: none; */
|
79 |
resize: none;
|
80 |
border: none;
|
|
|
81 |
/* -webkit-text-fill-color: rgba(82, 82, 82, 1) !important; */
|
82 |
/* color: rgba(82, 82, 82, 1) !important; */
|
83 |
|
84 |
/* background-color: var(--background-fill-secondary); */
|
85 |
}
|
86 |
|
87 |
-
.result-
|
88 |
-
|
|
|
89 |
}
|
90 |
|
91 |
-
.result-
|
92 |
-
|
93 |
-
gap: var(--block-padding);
|
94 |
-
padding: var(--block-padding);
|
95 |
-
flex-grow: 0 !important;
|
96 |
}
|
97 |
|
98 |
-
.result-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
position: relative;
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
font-weight: var(--block-title-text-weight);
|
108 |
-
font-size: var(--block-title-text-size);
|
109 |
-
line-height: var(--line-sm);
|
110 |
}
|
111 |
|
112 |
.modal .modal-container .modal-block{
|
|
|
73 |
}
|
74 |
|
75 |
.read-only label textarea,input {
|
76 |
+
cursor: text;
|
77 |
/* border: none;
|
78 |
box-shadow: none; */
|
79 |
resize: none;
|
80 |
border: none;
|
81 |
+
background-color: var(--block-background-fill);
|
82 |
/* -webkit-text-fill-color: rgba(82, 82, 82, 1) !important; */
|
83 |
/* color: rgba(82, 82, 82, 1) !important; */
|
84 |
|
85 |
/* background-color: var(--background-fill-secondary); */
|
86 |
}
|
87 |
|
88 |
+
.result-root {
|
89 |
+
background-color: var(--block-background-fill) !important;
|
90 |
+
padding: var(--block-padding) !important;
|
91 |
}
|
92 |
|
93 |
+
.result-root span label span {
|
94 |
+
display: none;
|
|
|
|
|
|
|
95 |
}
|
96 |
|
97 |
+
.result-root span label {
|
98 |
+
border: solid var(--block-title-border-width) var(--block-title-border-color) !important;
|
99 |
+
border-radius: var(--block-title-radius) !important;
|
100 |
+
background: var(--block-title-background-fill) !important;
|
101 |
+
padding: var(--block-title-padding) !important;
|
102 |
+
color: var(--block-title-text-color) !important;
|
103 |
+
font-weight: var(--block-title-text-weight) !important;
|
104 |
+
font-size: var(--block-title-text-size) !important;
|
105 |
+
line-height: var(--line-sm) !important;
|
106 |
position: relative;
|
107 |
+
top: 0 !important;
|
108 |
+
left: 0 !important;
|
109 |
+
}
|
110 |
+
|
111 |
+
.result-root .pending .prose {
|
112 |
+
min-height: 44px;
|
|
|
|
|
|
|
113 |
}
|
114 |
|
115 |
.modal .modal-container .modal-block{
|