Commit
·
d519348
1
Parent(s):
55a67a5
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
|
| 4 |
-
# Load pre-trained
|
| 5 |
-
|
| 6 |
-
model = MarianMTModel.from_pretrained(model_name)
|
| 7 |
-
tokenizer = MarianTokenizer.from_pretrained(model_name)
|
| 8 |
|
| 9 |
-
# Define the
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 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=
|
| 25 |
-
inputs=gr.Textbox(),
|
| 26 |
outputs=gr.Textbox(),
|
| 27 |
live=True,
|
| 28 |
-
title="
|
| 29 |
-
description="
|
| 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()
|
|
|