Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,42 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
|
|
3 |
QA_modelo = pipeline('question-answering', model='deepset/roberta-base-squad2')
|
4 |
|
|
|
5 |
def obter_resposta(pergunta, contexto):
|
6 |
-
|
7 |
|
|
|
8 |
contextos = {
|
9 |
-
"How do I create an account?": "You can create an account by clicking on the 'Sign Up' button on our homepage
|
10 |
-
"Which payment methods do you accept?": "We accept a wide range of payment methods including Visa, MasterCard
|
11 |
-
"How can I track my order?": "Once your order has shipped, you will receive an email with a tracking number
|
12 |
-
"Do you offer international shipping?": "Yes, we offer international shipping to most countries
|
13 |
-
"How long does delivery take?": "For standard shipping, deliveries typically take between 3 to 5 business days
|
14 |
-
"What is your return policy?": "Our return policy allows you to return products within 30 days of receiving them
|
15 |
-
"Can I change or cancel my order after it's been placed?": "You can change or cancel your order within 24 hours
|
16 |
-
"What should I do if I receive a damaged item?": "If you receive a damaged item, please contact our customer service
|
17 |
-
"How do I reset my password?": "If you've forgotten your password, go to the login page and click on 'Forgot Password'
|
18 |
}
|
19 |
|
|
|
20 |
def respondendo_faq(pergunta):
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
25 |
|
|
|
26 |
app = gr.Interface(
|
27 |
fn=respondendo_faq,
|
28 |
inputs=gr.Dropdown(choices=list(contextos.keys()), label="Select your question"),
|
29 |
-
outputs=
|
30 |
title='E-commerce FAQ',
|
31 |
-
description='Select a question to get an answer from our FAQ.'
|
|
|
32 |
|
33 |
if __name__ == "__main__":
|
34 |
app.launch(share=True)
|
35 |
-
|
36 |
-
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
|
4 |
+
# Carregando o modelo de QA
|
5 |
QA_modelo = pipeline('question-answering', model='deepset/roberta-base-squad2')
|
6 |
|
7 |
+
# Função para obter resposta com o modelo
|
8 |
def obter_resposta(pergunta, contexto):
|
9 |
+
return QA_modelo(question=pergunta, context=contexto)
|
10 |
|
11 |
+
# Dicionário com perguntas e contextos
|
12 |
contextos = {
|
13 |
+
"How do I create an account?": "You can create an account by clicking on the 'Sign Up' button on our homepage...",
|
14 |
+
"Which payment methods do you accept?": "We accept a wide range of payment methods including Visa, MasterCard...",
|
15 |
+
"How can I track my order?": "Once your order has shipped, you will receive an email with a tracking number...",
|
16 |
+
"Do you offer international shipping?": "Yes, we offer international shipping to most countries...",
|
17 |
+
"How long does delivery take?": "For standard shipping, deliveries typically take between 3 to 5 business days...",
|
18 |
+
"What is your return policy?": "Our return policy allows you to return products within 30 days of receiving them...",
|
19 |
+
"Can I change or cancel my order after it's been placed?": "You can change or cancel your order within 24 hours...",
|
20 |
+
"What should I do if I receive a damaged item?": "If you receive a damaged item, please contact our customer service...",
|
21 |
+
"How do I reset my password?": "If you've forgotten your password, go to the login page and click on 'Forgot Password'..."
|
22 |
}
|
23 |
|
24 |
+
# Função para responder perguntas da FAQ
|
25 |
def respondendo_faq(pergunta):
|
26 |
+
contexto = contextos.get(pergunta) # Verifica se a pergunta existe no dicionário
|
27 |
+
if not contexto:
|
28 |
+
return "Pergunta não encontrada. Selecione uma pergunta válida."
|
29 |
+
resultado = obter_resposta(pergunta, contexto)
|
30 |
+
return resultado['answer']
|
31 |
|
32 |
+
# Interface Gradio
|
33 |
app = gr.Interface(
|
34 |
fn=respondendo_faq,
|
35 |
inputs=gr.Dropdown(choices=list(contextos.keys()), label="Select your question"),
|
36 |
+
outputs=gr.Textbox(label="Answer"),
|
37 |
title='E-commerce FAQ',
|
38 |
+
description='Select a question to get an answer from our FAQ.'
|
39 |
+
)
|
40 |
|
41 |
if __name__ == "__main__":
|
42 |
app.launch(share=True)
|
|
|
|