Commit
•
b0c4c0f
1
Parent(s):
e9af536
more UI changes
Browse files
app.py
CHANGED
@@ -81,14 +81,16 @@ def retrieve_relevant_text(input_text):
|
|
81 |
|
82 |
# Extract code and similarity scores
|
83 |
output = []
|
84 |
-
for metadata, distance in zip(results['metadatas'][0], results['distances'][0]):
|
85 |
-
output.append(
|
86 |
-
"
|
87 |
-
"
|
88 |
-
"
|
89 |
-
"
|
90 |
-
|
91 |
-
|
|
|
|
|
92 |
|
93 |
# Evaluate retrieval efficiency on the validation/test set
|
94 |
def evaluate_efficiency(dataset_split):
|
@@ -125,11 +127,7 @@ precision, recall, f1 = evaluate_efficiency(dataset['validation'])
|
|
125 |
# Gradio interface
|
126 |
def gradio_interface(input_text):
|
127 |
results = retrieve_relevant_text(input_text)
|
128 |
-
|
129 |
-
f"Similarity Score: {result['similarity_score']:.2f}, Code: {result['code']}, Description: {result['description']}"
|
130 |
-
for result in results
|
131 |
-
]
|
132 |
-
return formatted_results
|
133 |
|
134 |
# Display retrieval efficiency metrics
|
135 |
metrics = f"Precision: {precision:.2f}, Recall: {recall:.2f}, F1 Score: {f1:.2f}"
|
@@ -137,9 +135,12 @@ metrics = f"Precision: {precision:.2f}, Recall: {recall:.2f}, F1 Score: {f1:.2f}
|
|
137 |
with gr.Blocks() as interface:
|
138 |
gr.Markdown("# Text Retrieval with Efficiency Metrics")
|
139 |
gr.Markdown(metrics)
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
143 |
submit_button.click(fn=gradio_interface, inputs=text_input, outputs=text_output)
|
144 |
|
145 |
interface.launch()
|
|
|
81 |
|
82 |
# Extract code and similarity scores
|
83 |
output = []
|
84 |
+
for i, (metadata, distance) in enumerate(zip(results['metadatas'][0], results['distances'][0])):
|
85 |
+
output.append(
|
86 |
+
f"Result {i + 1}:\n"
|
87 |
+
f"Similarity Score: {distance:.2f}\n"
|
88 |
+
f"Code: {metadata['code']}\n"
|
89 |
+
f"Code System: {metadata['code_system']}\n"
|
90 |
+
f"Description: {metadata['description']}\n"
|
91 |
+
"-------------------"
|
92 |
+
)
|
93 |
+
return "\n".join(output)
|
94 |
|
95 |
# Evaluate retrieval efficiency on the validation/test set
|
96 |
def evaluate_efficiency(dataset_split):
|
|
|
127 |
# Gradio interface
|
128 |
def gradio_interface(input_text):
|
129 |
results = retrieve_relevant_text(input_text)
|
130 |
+
return results
|
|
|
|
|
|
|
|
|
131 |
|
132 |
# Display retrieval efficiency metrics
|
133 |
metrics = f"Precision: {precision:.2f}, Recall: {recall:.2f}, F1 Score: {f1:.2f}"
|
|
|
135 |
with gr.Blocks() as interface:
|
136 |
gr.Markdown("# Text Retrieval with Efficiency Metrics")
|
137 |
gr.Markdown(metrics)
|
138 |
+
with gr.Row():
|
139 |
+
with gr.Column():
|
140 |
+
text_input = gr.Textbox(label="Input Text")
|
141 |
+
submit_button = gr.Button("Submit")
|
142 |
+
with gr.Column():
|
143 |
+
text_output = gr.Textbox(label="Retrieved Results")
|
144 |
submit_button.click(fn=gradio_interface, inputs=text_input, outputs=text_output)
|
145 |
|
146 |
interface.launch()
|