import subprocess subprocess.run(["python", "-m", "ensurepip", "--upgrade"], check=True) title = "Q&A using Semantic Search 🔍" desc = """
This is a Question & Answering app that uses semantic search to retrieve results. Semantic search means understanding the intent behind the query and representing the “knowledge in a way suitable for meaningful retrieval”.
Note: For faster results input smaller contexts'p>
Sample context and question inputs are provided at the bottom! Click on them to popluate the search box
""" # distilled model: "deepset/tinyroberta-squad2", "deepset/xlm-roberta-base-squad2", "keras-io/transformers-qa" model_name = "deepset/tinyroberta-squad2" import gradio as gr context1 = """ Subject: Staffdel Valeo Reservations for Mr. Valeo have been made at Hyatt hotel November 11 - 15. Ambassador has issued invitations for dinner in Mr. Valeo's honor November 14 to government officials, political figures, journalists, and businessmen who have associations with various aspects of China question. Ambassador would also like invite Mr. Valeo to dinner he is giving November 12 in honor archbishop sin, who is new and impressive figure on Philippine national scene. Guests will be prominent clerical and lay leaders of church who can give Mr. Valeo interesting perspective on their current outlook. Requested briefings will be arranged at embassy on November 12. Please advise if Mr. Valeo has other program interests, he wishes us to arrange in advance his arrival. As Mr. Valeo probably knows, Mrs. Marcos, governor """ question1 = "When is the Hyattt Hottel reservation?" context2 = """ Subject: Travel of Charles Engelhardt, Sikorsky rep Mr. Charles Engelhardt of Sikorsky aircraft will be visiting your posts during the following dates. He will check in with embassies on arrival and any assistance would be appreciated. Hotel reservations have been made, Abidjan 6 Nov-Nov 8; Conakry Nov 8-Nov 11; Accra Nov 12-15; Lagos Nov 15- Nov 19; Addis Nov 20-Nov 22; Khartoum Nov 22- Nov 26. """ question2 = "When is the Khartoum reservation?" context3 = """ Subject: Travel of UN official Mr. Roland de Lagerie, P-5 chief of UN office Geneva secretariat recruitment and training, will be in New York for consultations with UN HQS 11 through 15 November 1974. His schedule will not permit him to travel to Washington to visit the department (as suggested by Kevin Carroll), but he said he would be happy to meet with our officers in New York. Those who wish to see de Lagerie can reach him through the office of Mr. Bob Webb, director division of recruitment. Although his hands appear tied by superiors in New York, and he therefore does not want his name involved, de Lagerie would appreciate anything that could be done to streamline procedures for submission of requests for executive order 10422 clearances. Mission would be pleased to forward forms direct to csc (as is case for every other UNOG in Geneva), but UNOG is obliged send them to New York which has caused unnecessary delays and problems. """ question3 = "Who is Bob Web?" #key = "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" demo= gr.Interface.load( "huggingface/" + model_name, theme="dark-peach", #api_key = key, examples = [[context1, question1],[context2, question2], [context3, question3]], css=".footer{display:none !important}", #inputs=[gr.Textbox(lines=7, default=context1, label="Context"), gr.inputs.Textbox(lines=2, default=question1, label="Question")], #outputs=[gr.Textbox(label="Answer"),gr.outputs.Textbox(label="Score")], description=desc, title=title ) demo.launch()