Allen Park commited on
Commit
31afd70
·
1 Parent(s): 6b5935b

feat(add clickable examples)

Browse files
Files changed (1) hide show
  1. app.py +46 -1
app.py CHANGED
@@ -41,6 +41,39 @@ Your output should be in JSON FORMAT with the keys "REASONING" and "SCORE":
41
  {{"REASONING": <your reasoning as bullet points>, "SCORE": <your final score>}}
42
  """
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  css = """
45
  @import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;700&display=swap');
46
 
@@ -167,13 +200,16 @@ def upload_file(filepath):
167
  extracted_file_text = extract_text_pymupdf(filepath)
168
  elif filetype == "docx":
169
  extracted_file_text = extract_text_python_docx(filepath)
170
- return [gr.UploadButton(visible=False), gr.Group(visible=True), gr.Markdown("**Uploaded file:** {name}".format(name=name)), extracted_file_text]
171
  else:
172
  return [gr.UploadButton(visible=True, file_count="single", file_types=UPLOADABLE_FILE_TYPES), gr.Group(visible=False), gr.Markdown(""), extracted_file_text]
173
  # return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download {name}", value=filepath, visible=True)]
174
  def reset_buttons():
175
  return [gr.UploadButton(visible=True, file_count="single", file_types=UPLOADABLE_FILE_TYPES), gr.Group(visible=False), gr.Markdown(""), gr.Textbox(value="")]
176
 
 
 
 
177
  # def download_file():
178
  # return [gr.UploadButton(visible=True), gr.DownloadButton(visible=False)]
179
 
@@ -209,6 +245,15 @@ with gr.Blocks(css=css) as demo:
209
  with gr.Row():
210
  clear_btn = gr.ClearButton([question, document, answer])
211
  submit_button = gr.Button("Submit")
 
 
 
 
 
 
 
 
 
212
  with gr.Column(scale=1):
213
  reasoning = gr.Textbox(label="Reasoning")
214
  score = gr.Textbox(label="Score (FAIL if Hallucinated, PASS if not)")
 
41
  {{"REASONING": <your reasoning as bullet points>, "SCORE": <your final score>}}
42
  """
43
 
44
+ EXAMPLES = [
45
+ {
46
+ "emoji": "🏈",
47
+ "question": "Which player had the longest touchdown play of the first half?",
48
+ "document": "The Browns dropped their 13th consecutive season-opening game with a 21-18 loss to the Steelers. The scoring began early in the first quarter when Pittsburgh's Tyler Matakevich blocked a Britton Colquitt punt, knocking the ball into the end zone where it was recovered by Anthony Chickillo for a touchdown. The Browns were able to tie the score by the end of the first quarter, however, as rookie quarterback DeShone Kizer orchestrated a 12-play drive that ended when he scored on a 1-yard touchdown run. The game stayed at 7-7 through most of the second quarter, until the Steelers quarterback Ben Roethlisberger connected with tight end Jesse James on a 4-yard touchdown with 45 seconds left in the first half. The 7-play, 91-yard scoring drive was highlighted by a 50-yard reception by Antonio Brown on a tipped ball. After a Zane Gonzalez field goal brought the Browns within 14-10 early in the third quarter, the Steelers drove down the field again. Roethlisberger threw a second touchdown pass to James to put them up by 11, 21-10. The drive was boosted by a 41-yard pass interference penalty on Browns cornerback Jamar Taylor on a deep pass intended for Brown. The score remained 21-10 until under four minutes remained in the game, when Kizer was able to throw his first career touchdown pass to Corey Coleman. A two-point conversion run by Isaiah Crowell brought the Browns to within a field goal, 21-18. The Browns did not get a chance to score again, however, as the Steelers were able to run out the clock after a long pass from Roethlisberger to Brown. Browns head coach Hue Jackson challenged the ruling; however, the catch call on the field was upheld. The 13th-straight season-opening loss extended an NFL record for the Browns, who also fell to 1-18 in season openers since returning to the league in 1999. The team also lost their 12th straight game against a divisional opponent. The team started 0-1.",
49
+ "answer": "['Antonio Brown']"
50
+ },
51
+ {
52
+ "emoji": "🎾",
53
+ "question": "Who lost to Petrova in the Australian Open?",
54
+ "document": "Coming off their road win over the Redskins, the Chiefs went home, donned their Dallas Texans throwbacks, and played a Week 7 AFL Legacy game with the San Diego Chargers. Kansas City would find themselves trailing in the first quarter as Chargers quarterback Philip Rivers completed a 3-yard touchdown pass to wide receiver Malcom Floyd, followed by a 10-yard touchdown pass to wide receiver Vincent Jackson. San Diego would add onto their lead in the second quarter with a 20-yard and a 39-yard field goal from kicker Nate Kaeding. The Chiefs would get onto the board in the third quarter with quarterback Matt Cassel completing a 7-yard touchdown pass to wide receiver Dwayne Bowe, but the Chargers kept their momentum going with Rivers finding running back Darren Sproles on a 58-yard touchdown pass. In the fourth quarter, San Diego sealed the win with Kaeding's 19-yard field goal and fullback Jacob Hester recovering a blocked punt in the end zone for a touchdown. With the loss, Kansas City went into their bye week at 1-6. Larry Johnson was suspended for two weeks after he made offensive comments about Todd Haley and made offensive comments about homosexuals on Twitter and in public.",
55
+ "answer": "['Maria Sharapova', 'Venus Williams', 'Svetlana Kuznetsova']"
56
+ },
57
+ {
58
+ "emoji": "⛪️",
59
+ "question": "Whose Apology was rejected by Charles V?",
60
+ "document": "In the course of the Lutheran Reformation numerous Imperial States had adopted the new confession, against the opposition of the ruling Catholic House of Habsburg, who recognised these conversions as a quest for increasing autonomy to the detriment of the central Imperial authority. At the 1521 Diet of Worms Emperor Charles V had Martin Luther banned and the proliferation of his writings prohibited, which in 1529 provoked the Protestation at Speyer by several Lutheran estates. The tensions culminated to an open conflict over the Lutheran Augsburg Confession of 1530, the Apology of which, written by Philipp Melanchthon, was rejected by the Emperor. In turn several Lutheran states led by Elector John Frederick I of Saxony and Landgrave Philip I of Hesse met at the town of Schmalkalden, where they established the Schmalkaldic League in 1531. In 1544 Charles V returned to Germany from the Italian War after he had signed the Treaty of Crépy and began to forge alliances not only with Pope Paul III but also with Lutheran princes, foremost with Duke Maurice of Saxony, the Albertine cousin of Saxon Elector John Frederick I. In view of the Emperor's preparations for battle, the Schmalkaldic leaders on 4 July 1546 gathered at Ichtershausen and agreed that a preventive strike would be advisable, as long as Charles V had not concentrated a significant amount of mercenaries. The Emperor gathered an army of around 52,000 men for his campaign, that was to start on the Danube.",
61
+ "answer": "Martin Luther"
62
+ },
63
+ {
64
+ "emoji": "🪖",
65
+ "question": "What battle started first: Battle of Vienna or Battle of Mohács?",
66
+ "document": "The Siege of Vienna in 1529 was the first attempt by the Ottoman Empire, led by Suleiman the Magnificent, to capture the city of Vienna, Austria. The siege signalled the pinnacle of the Ottoman Empire's power and the maximum extent of Ottoman expansion in central Europe. Thereafter, 150 years of bitter military tension and reciprocal attacks ensued, culminating in the Battle of Vienna of 1683, which marked the start of the 15-year-long Great Turkish War. The inability of the Ottomans to capture Vienna in 1529 turned the tide against almost a century of conquest throughout eastern and central Europe. The Ottoman Empire had previously annexed Central Hungary and established a vassal state in Transylvania in the wake of the Battle of Mohács. According to Arnold J. Toynbee, 'The failure of the first brought to a standstill the tide of Ottoman conquest which had been flooding up the Danube Valley for a century past.' There is speculation by some historians that Suleiman's main objective in 1529 was actually to assert Ottoman control over the whole of Hungary, the western part of which was under Habsburg control. The decision to attack Vienna after such a long interval in Suleiman's European campaign is viewed as an opportunistic manoeuvre after his decisive victory in Hungary. Other scholars theorise that the suppression of Hungary simply marked the prologue to a later, premeditated invasion of Europe.",
67
+ "answer": "Battle of Vienna"
68
+ },
69
+ {
70
+ "emoji": "🏰",
71
+ "question": "What American businessman and guided the character Epick Mickey?",
72
+ "document": "The character was regained by The Walt Disney Company in 2006 under the guidance of Bob Iger.Robert Allen Iger ( ; born February 10, 1951) is an American businessman who is chairman and chief executive officer (CEO) of The Walt Disney Company.",
73
+ "answer": "Walt Disney himself guided Epic Mickey."
74
+ }
75
+ ]
76
+
77
  css = """
78
  @import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;700&display=swap');
79
 
 
200
  extracted_file_text = extract_text_pymupdf(filepath)
201
  elif filetype == "docx":
202
  extracted_file_text = extract_text_python_docx(filepath)
203
+ return [gr.UploadButton(visible=False), gr.Group(visible=True), gr.Markdown(f"**Uploaded file:** {name}"), extracted_file_text]
204
  else:
205
  return [gr.UploadButton(visible=True, file_count="single", file_types=UPLOADABLE_FILE_TYPES), gr.Group(visible=False), gr.Markdown(""), extracted_file_text]
206
  # return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download {name}", value=filepath, visible=True)]
207
  def reset_buttons():
208
  return [gr.UploadButton(visible=True, file_count="single", file_types=UPLOADABLE_FILE_TYPES), gr.Group(visible=False), gr.Markdown(""), gr.Textbox(value="")]
209
 
210
+ def select_template(template):
211
+ return template["question"], template["document"], template["answer"]
212
+
213
  # def download_file():
214
  # return [gr.UploadButton(visible=True), gr.DownloadButton(visible=False)]
215
 
 
245
  with gr.Row():
246
  clear_btn = gr.ClearButton([question, document, answer])
247
  submit_button = gr.Button("Submit")
248
+ with gr.Row():
249
+ gr.Markdown("### Example Templates")
250
+ for idx, example in enumerate(EXAMPLES):
251
+ template_btn = gr.Button(f"{example['emoji']} {example['question']}")
252
+ template_btn.click(
253
+ fn=select_template,
254
+ inputs=[gr.State(example)],
255
+ outputs=[question, document, answer]
256
+ )
257
  with gr.Column(scale=1):
258
  reasoning = gr.Textbox(label="Reasoning")
259
  score = gr.Textbox(label="Score (FAIL if Hallucinated, PASS if not)")