Test_Lesya / app.py
AlexDataMedWork's picture
Update app.py
64a3058 verified
import gradio as gr
import json
# --- зчитування 3 джерел ---
with open("analysis_explanations_1.json", encoding="utf-8") as f1:
data1 = json.load(f1)
with open("analysis_explanations_2.json", encoding="utf-8") as f2:
data2 = json.load(f2)
try:
with open("analyses_results.json", encoding="utf-8") as f3:
data3 = json.load(f3)
except FileNotFoundError:
data3 = []
# --- перетворення у словники: {input -> output} ---
dict1 = {entry["input"]: entry["output"] for entry in data1}
dict2 = {entry["input"]: entry["output"] for entry in data2}
dict3 = {entry["input"]: entry["output"] for entry in data3}
# --- список унікальних аналізів ---
analysis_options = sorted(set(list(dict1.keys()) + list(dict2.keys()) + list(dict3.keys())))
def explain_analysis_separately(selected_test):
output1 = dict1.get(selected_test, "Немає у першому джерелі.")
output2 = dict2.get(selected_test, "Немає у другому джерелі.")
output3 = dict3.get(selected_test, "Немає у третьому джерелі.")
return output1, output2, output3
with gr.Blocks() as demo:
gr.Markdown("## 🧪 Пояснення до аналізів з трьох джерел")
with gr.Row():
test_dropdown = gr.Dropdown(label="Оберіть аналіз", choices=analysis_options)
with gr.Row():
output1 = gr.Textbox(label="Варіант 1 (analysis_explanations_1.json)", lines=8)
output2 = gr.Textbox(label="Варіант 2 (analysis_explanations_2.json)", lines=8)
output3 = gr.Textbox(label="Варіант 3 (analyses_results.json)", lines=8)
test_dropdown.change(
fn=explain_analysis_separately,
inputs=test_dropdown,
outputs=[output1, output2, output3]
)
demo.launch()