hgdgng commited on
Commit
05d9728
·
verified ·
1 Parent(s): ad9b612

Create HGapp.py

Browse files
Files changed (1) hide show
  1. HGapp.py +22 -0
HGapp.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the pre-trained question-answering model from Hugging Face
5
+ qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
6
+
7
+ # Define the function that takes inputs and returns the answer
8
+ def answer_question(context, question):
9
+ result = qa_pipeline(question=question, context=context)
10
+ return result['answer']
11
+
12
+ # Create the Gradio interface
13
+ interface = gr.Interface(
14
+ fn=answer_question,
15
+ inputs=[gr.inputs.Textbox(lines=7, label="Context (Enter the passage)"), gr.inputs.Textbox(lines=2, label="Question")],
16
+ outputs="text",
17
+ title="Question Answering Model",
18
+ description="Ask a question based on the given context.",
19
+ )
20
+
21
+ # Launch the interface
22
+ interface.launch()