Stkong commited on
Commit
ae31f55
1 Parent(s): a765b25

Add application file

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  # Example context and question
2
  example_1 = "The galaxy is in the midst of a civil war. Spies for the Rebel Alliance have stolen plans to the Galactic Empire's Death Star, a heavily armed space station capable of destroying planets. Rebel leader Princess Leia has the plans, but her ship is captured by Imperial forces under the command of the evil Darth Vader. Before she is captured, Leia hides the plans in the memory of an astromech droid, R2-D2, along with a holographic recording. The droid flees to the surface of the desert planet Tatooine with C-3PO, a protocol droid. The droids are captured by Jawa traders, who sell them to moisture farmers Owen and Beru Lars and their nephew, Luke Skywalker. While cleaning R2-D2, Luke accidentally triggers part of Leia's message, in which she requests help from Obi-Wan Kenobi. The next morning, Luke finds R2-D2 searching for Obi-Wan, and meets Ben Kenobi, an old hermit who lives in the hills and reveals himself to be Obi-Wan. Obi-Wan tells Luke of his days as a Jedi Knight, former Galactic Republic peacekeepers with supernatural powers derived from an energy called The Force, who were all but wiped out by the Empire. Contrary to his uncle's statements, Luke learns that his father, Anakin, fought alongside Obi-Wan as a Jedi Knight. Obi-Wan tells Luke that Vader was his former pupil who turned to the dark side of the Force and killed Anakin. Obi-Wan presents Luke his father's weapon - a lightsaber. Obi-Wan views Leia's complete message, in which she begs him to take the Death Star plans to her home planet of Alderaan and give them to her father for analysis. Obi-Wan invites Luke to accompany him to Alderaan and learn the ways of the Force. Luke declines, but changes his mind after discovering that Imperial stormtroopers searching for C-3PO and R2-D2 have destroyed his home and killed his aunt and uncle. Obi-Wan and Luke hire smuggler Han Solo and his Wookiee first mate Chewbacca to transport them to Alderaan on Han's ship, the Millennium Falcon. Upon the Falcon's arrival at the location of Alderaan, the group discover that the planet has been destroyed by order of the Death Star's commanding officer, Grand Moff Tarkin, as a show of power. The Falcon is captured by the Death Star's tractor beam and brought into its hangar bay. While Obi-Wan goes to disable the tractor beam, Luke discovers that Leia is imprisoned aboard, and with the help of Han and Chewbacca, rescues her. After several escapes, the group makes its way back to the Falcon. Obi-Wan disables the tractor beam, and on the way back to the Falcon, he engages in a lightsaber duel with Vader. Once he is sure the others can escape, Obi-Wan allows himself to be killed. The Falcon escapes the Death Star, unknowingly carrying a tracking beacon, which the Empire follows to the Rebels' hidden base on Yavin IV. The Rebels analyze the Death Star's plans and identify a vulnerable exhaust port that connects to the station's main reactor. Luke joins the Rebel assault squadron, while Han collects his payment for the transport and intends to leave, despite Luke's request that he stay and help. In the ensuing battle, the Rebels suffer heavy losses after several unsuccessful attack runs, leaving Luke as one of the few surviving pilots. Vader leads a squad of TIE fighters and prepares to attack Luke's X-wing fighter, but Han returns and fires on the Imperials, sending Vader spiraling away. Helped by guidance from Obi-Wan's spirit, Luke uses the Force and successfully destroys the Death Star seconds before it can fire on the Rebel base. Leia awards Luke and Han with medals for their heroism."
3
  qst_1 = "What is a Jedi's main weapon?"
@@ -15,19 +16,20 @@ from transformers import pipeline
15
  # Initialize two different pipelines
16
  model1 = pipeline("question-answering", model="suthanhcong/bert-finetuned-squad-finetuned-DouRC_squad")
17
  model3 = pipeline("question-answering", model="suthanhcong/roberta-base-squad2-finetuned-DouRC_squad")
18
- model2 = pipeline("question-answering", model="suthanhcong/distilbert-base-uncased-finetuned-DouRC_squad")
19
 
20
  # Function to get answers from both models
21
  def func(question, ground_truth, context):
22
- result1 = model1(question=question, context=context)
23
- result2 = model2(question=question, context=context)
24
- result3 = model3(question=question, context=context)
25
  # Prepare the results as dictionaries
26
- result1_dict = {"Model 1": result1}
27
- result2_dict = {"Model 2": result2}
28
- result3_dict = {"Model 3": result3}
29
  ground_truth_dict = {"Ground Truth": ground_truth}
30
- return ground_truth_dict, result1_dict, result2_dict, result3_dict
 
31
 
32
 
33
  # Creating the interface
@@ -41,8 +43,8 @@ app = gr.Interface(
41
  outputs=[
42
  gr.JSON(label="Ground Truth"),
43
  gr.JSON(label="BERT"),
44
- gr.JSON(label="DistilBERT base uncased"),
45
- gr.JSON(label="RoBERTa base uncased"),
46
  ],
47
  theme = gr.Theme.from_hub("bethecloud/storj_theme"),
48
  title='Question Answering Bot with Two Models and Ground Truth',
@@ -53,3 +55,4 @@ app = gr.Interface(
53
  # Launch the app
54
  app.launch(inline=False)
55
 
 
 
1
+
2
  # Example context and question
3
  example_1 = "The galaxy is in the midst of a civil war. Spies for the Rebel Alliance have stolen plans to the Galactic Empire's Death Star, a heavily armed space station capable of destroying planets. Rebel leader Princess Leia has the plans, but her ship is captured by Imperial forces under the command of the evil Darth Vader. Before she is captured, Leia hides the plans in the memory of an astromech droid, R2-D2, along with a holographic recording. The droid flees to the surface of the desert planet Tatooine with C-3PO, a protocol droid. The droids are captured by Jawa traders, who sell them to moisture farmers Owen and Beru Lars and their nephew, Luke Skywalker. While cleaning R2-D2, Luke accidentally triggers part of Leia's message, in which she requests help from Obi-Wan Kenobi. The next morning, Luke finds R2-D2 searching for Obi-Wan, and meets Ben Kenobi, an old hermit who lives in the hills and reveals himself to be Obi-Wan. Obi-Wan tells Luke of his days as a Jedi Knight, former Galactic Republic peacekeepers with supernatural powers derived from an energy called The Force, who were all but wiped out by the Empire. Contrary to his uncle's statements, Luke learns that his father, Anakin, fought alongside Obi-Wan as a Jedi Knight. Obi-Wan tells Luke that Vader was his former pupil who turned to the dark side of the Force and killed Anakin. Obi-Wan presents Luke his father's weapon - a lightsaber. Obi-Wan views Leia's complete message, in which she begs him to take the Death Star plans to her home planet of Alderaan and give them to her father for analysis. Obi-Wan invites Luke to accompany him to Alderaan and learn the ways of the Force. Luke declines, but changes his mind after discovering that Imperial stormtroopers searching for C-3PO and R2-D2 have destroyed his home and killed his aunt and uncle. Obi-Wan and Luke hire smuggler Han Solo and his Wookiee first mate Chewbacca to transport them to Alderaan on Han's ship, the Millennium Falcon. Upon the Falcon's arrival at the location of Alderaan, the group discover that the planet has been destroyed by order of the Death Star's commanding officer, Grand Moff Tarkin, as a show of power. The Falcon is captured by the Death Star's tractor beam and brought into its hangar bay. While Obi-Wan goes to disable the tractor beam, Luke discovers that Leia is imprisoned aboard, and with the help of Han and Chewbacca, rescues her. After several escapes, the group makes its way back to the Falcon. Obi-Wan disables the tractor beam, and on the way back to the Falcon, he engages in a lightsaber duel with Vader. Once he is sure the others can escape, Obi-Wan allows himself to be killed. The Falcon escapes the Death Star, unknowingly carrying a tracking beacon, which the Empire follows to the Rebels' hidden base on Yavin IV. The Rebels analyze the Death Star's plans and identify a vulnerable exhaust port that connects to the station's main reactor. Luke joins the Rebel assault squadron, while Han collects his payment for the transport and intends to leave, despite Luke's request that he stay and help. In the ensuing battle, the Rebels suffer heavy losses after several unsuccessful attack runs, leaving Luke as one of the few surviving pilots. Vader leads a squad of TIE fighters and prepares to attack Luke's X-wing fighter, but Han returns and fires on the Imperials, sending Vader spiraling away. Helped by guidance from Obi-Wan's spirit, Luke uses the Force and successfully destroys the Death Star seconds before it can fire on the Rebel base. Leia awards Luke and Han with medals for their heroism."
4
  qst_1 = "What is a Jedi's main weapon?"
 
16
  # Initialize two different pipelines
17
  model1 = pipeline("question-answering", model="suthanhcong/bert-finetuned-squad-finetuned-DouRC_squad")
18
  model3 = pipeline("question-answering", model="suthanhcong/roberta-base-squad2-finetuned-DouRC_squad")
19
+ # model2 = pipeline("question-answering", model="suthanhcong/distilbert-base-uncased-finetuned-DouRC_squad")
20
 
21
  # Function to get answers from both models
22
  def func(question, ground_truth, context):
23
+ # result1 = model1(question=question, context=context)
24
+ # result2 = model2(question=question, context=context)
25
+ result1 = model3(question=question, context=context)
26
  # Prepare the results as dictionaries
27
+ result1_dict = {"Answer": result1['answer']}
28
+ # result2_dict = {"Model 2": result2}
29
+ # result3_dict = {"Model 3": result3}
30
  ground_truth_dict = {"Ground Truth": ground_truth}
31
+ return ground_truth_dict, result1_dict
32
+ # , result2_dict, result3_dict
33
 
34
 
35
  # Creating the interface
 
43
  outputs=[
44
  gr.JSON(label="Ground Truth"),
45
  gr.JSON(label="BERT"),
46
+ # gr.JSON(label="DistilBERT base uncased"),
47
+ # gr.JSON(label="RoBERTa base uncased"),
48
  ],
49
  theme = gr.Theme.from_hub("bethecloud/storj_theme"),
50
  title='Question Answering Bot with Two Models and Ground Truth',
 
55
  # Launch the app
56
  app.launch(inline=False)
57
 
58
+