namddh commited on
Commit
0d01575
·
1 Parent(s): 079aa13

first commit

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +75 -0
  3. output_full.json +0 -0
README.md CHANGED
@@ -6,7 +6,7 @@ colorTo: pink
6
  sdk: gradio
7
  sdk_version: 5.12.0
8
  app_file: app.py
9
- pinned: false
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
6
  sdk: gradio
7
  sdk_version: 5.12.0
8
  app_file: app.py
9
+ pinned: true
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import gradio as gr
4
+
5
+
6
+ def load_output():
7
+ with open("evaluation/output1.json") as f:
8
+ return json.load(f)
9
+
10
+ with gr.Blocks(fill_width=True) as demo:
11
+ full_data = gr.State(load_output())
12
+ current_example = gr.State({})
13
+ current_index = gr.State(-1)
14
+
15
+ with gr.Row():
16
+
17
+ with gr.Column(scale=2):
18
+ @gr.render(inputs=current_example)
19
+ def show_question_and_answer(current_set):
20
+ input = current_set.get("input", "")
21
+ full_ans_1 = current_set.get("full_ans_1", "")
22
+ gold_ans_1 = current_set.get("gold_ans_1", "")
23
+ gold_ans_2 = current_set.get("gold_ans_2", "")
24
+
25
+ gr.Markdown("## " + input)
26
+ gr.TextArea(full_ans_1, container=True, label="RAFT Full answer")
27
+ gr.Markdown("### RAFT Answer\n" + gold_ans_1, container=True, label="gold_ans_1")
28
+ gr.Markdown("### Llama 3.2 3B\n" + gold_ans_2, container=True, label="gold_ans_2")
29
+
30
+ with gr.Column(variant="panel", scale=2):
31
+ gr.Markdown("## Documents used for response")
32
+
33
+ @gr.render(inputs=current_example)
34
+ def show_documents(example):
35
+ chunks = example.get("chunks", [])
36
+ gr.Markdown(f"> k={len(chunks)}", height=50)
37
+ for doc in chunks:
38
+ gr.Textbox(str(doc[1]), label=str(doc[0]), max_lines=10)
39
+
40
+
41
+ with gr.Column(scale=1):
42
+ with gr.Blocks():
43
+ def to_index(index, full_data):
44
+ index = max(0, min(index, len(full_data) - 1))
45
+ return [index - 1, full_data[index - 1]]
46
+
47
+ num_input = gr.Number(label="Go to example", minimum=1)
48
+ gr.Button("To index").click(to_index, [num_input, full_data], [current_index, current_example])
49
+
50
+ with gr.Blocks():
51
+ @gr.render(inputs=[current_index, full_data])
52
+ def show_index(current_index, full_data):
53
+ gr.Markdown(f"Example **{current_index + 1}** of **{len(full_data)}**", height=50)
54
+
55
+ with gr.Column():
56
+ def to_start(current_index, current_example, full_data):
57
+ return [0, full_data[0]]
58
+
59
+ def to_end(current_index, current_example, full_data):
60
+ return [len(full_data) - 1, full_data[-1]]
61
+
62
+ def next_example(current_index, current_example, full_data):
63
+ next_index = (current_index + 1) % len(full_data)
64
+ return [next_index, full_data[next_index]]
65
+
66
+ def prev_example(current_index, current_example, full_data):
67
+ prev_index = (current_index - 1) % len(full_data)
68
+ return [prev_index, full_data[prev_index]]
69
+
70
+ gr.Button("<| First").click(to_start, [current_index, current_example, full_data], [current_index, current_example])
71
+ gr.Button("<< Previous").click(prev_example, [current_index, current_example, full_data], [current_index, current_example])
72
+ gr.Button("Next >>").click(next_example, [current_index, current_example, full_data], [current_index, current_example])
73
+ gr.Button("Last |>").click(to_end, [current_index, current_example, full_data], [current_index, current_example])
74
+
75
+ demo.launch()
output_full.json ADDED
The diff for this file is too large to render. See raw diff