LovnishVerma commited on
Commit
d519348
·
1 Parent(s): 55a67a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -22
app.py CHANGED
@@ -1,34 +1,25 @@
1
  import gradio as gr
2
- from transformers import MarianMTModel, MarianTokenizer
3
 
4
- # Load pre-trained MarianMT model and tokenizer for translation
5
- model_name = "Helsinki-NLP/opus-mt-en-de"
6
- model = MarianMTModel.from_pretrained(model_name)
7
- tokenizer = MarianTokenizer.from_pretrained(model_name)
8
 
9
- # Define the translation function
10
- def translate_text(text):
11
- # Tokenize the input text
12
- inputs = tokenizer(text, return_tensors="pt")
13
-
14
- # Perform translation
15
- translation = model.generate(**inputs)
16
-
17
- # Decode the translated text
18
- translated_text = tokenizer.decode(translation[0], skip_special_tokens=True)
19
-
20
- return translated_text
21
 
22
  # Create Gradio interface
23
  iface = gr.Interface(
24
- fn=translate_text,
25
- inputs=gr.Textbox(),
26
  outputs=gr.Textbox(),
27
  live=True,
28
- title="Language Translation App",
29
- description="Translate text from English to German using MarianMT.",
30
  )
31
 
32
  # Launch the Gradio app
33
  iface.launch()
34
-
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Load pre-trained question-answering model
5
+ qa_model = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
 
 
6
 
7
+ # Define the question-answering function
8
+ def answer_question(context, question):
9
+ result = qa_model(context=context, question=question)
10
+ answer = result["answer"]
11
+ confidence = result["score"]
12
+ return f"Answer: {answer}\nConfidence: {confidence:.4f}"
 
 
 
 
 
 
13
 
14
  # Create Gradio interface
15
  iface = gr.Interface(
16
+ fn=answer_question,
17
+ inputs=[gr.Textbox(label="Context"), gr.Textbox(label="Question")],
18
  outputs=gr.Textbox(),
19
  live=True,
20
+ title="Question Answering System",
21
+ description="Enter a context and a question, and the model will provide an answer.",
22
  )
23
 
24
  # Launch the Gradio app
25
  iface.launch()