Spaces:
Sleeping
Sleeping
File size: 1,868 Bytes
6c9ca3a 64a3058 6c9ca3a 64a3058 0568946 64a3058 6c9ca3a 64a3058 6c9ca3a 0568946 64a3058 6c9ca3a 64a3058 6c9ca3a 0568946 64a3058 6c9ca3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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()
|