Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,26 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
model = AutoModelForCausalLM.from_pretrained("Evelyn18/roberta-base-spanish-squades-becasv3")
|
6 |
-
|
7 |
-
def predict(input, history=[]):
|
8 |
-
# tokenize the new input sentence
|
9 |
-
new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
10 |
-
|
11 |
-
# append the new user input tokens to the chat history
|
12 |
-
bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
13 |
|
14 |
-
|
15 |
-
history = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id).tolist()
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
cls = "user" if m%2 == 0 else "bot"
|
25 |
-
html += "<div class='msg {}'> {}</div>".format(cls, msg)
|
26 |
-
html += "</div>"
|
27 |
-
|
28 |
-
return html, history
|
29 |
|
30 |
-
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
.msg {padding:4px;margin-bottom:4px;border-radius:4px;width:80%}
|
35 |
-
.msg.user {background-color:cornflowerblue;color:white}
|
36 |
-
.msg.bot {background-color:lightgray;align-self:self-end}
|
37 |
-
.footer {display:none !important}
|
38 |
-
"""
|
39 |
|
40 |
-
gr.Interface(
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
from transformers import pipeline
|
4 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
model = pipeline('question-answering', model='deepset/tinyroberta-squad2', tokenizer='deepset/tinyroberta-squad2')
|
|
|
7 |
|
8 |
+
def qa(passage, question):
|
9 |
+
question = question
|
10 |
+
context = passage
|
11 |
+
nlp_input = {
|
12 |
+
'question': question,
|
13 |
+
'context': context
|
14 |
+
}
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
return model(nlp_input)['answer']
|
17 |
|
18 |
+
passage = "The quick brown fox jumped over the lazy dog."
|
19 |
+
question = "Who jumps over the lazy dog?"
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
iface = gr.Interface(qa,
|
22 |
+
title="Question Answering using RoBERTa",
|
23 |
+
inputs=[gr.inputs.Textbox(lines=15), "text"],
|
24 |
+
outputs=["text"],
|
25 |
+
examples=[["{}".format(passage), "{}".format(question)]])
|
26 |
+
iface.launch()
|