Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,33 @@
|
|
1 |
-
from transformers import GPTNeoForCausalLM, GPT2Tokenizer
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
p = prompt + input
|
27 |
-
input_ids = tokenizer(p, return_tensors="pt").input_ids
|
28 |
-
gen_tokens = model.generate(input_ids, do_sample=True, temperature=0.7, max_length=150,)
|
29 |
-
gen_text = tokenizer.batch_decode(gen_tokens)[0]
|
30 |
-
# print(gen_text)
|
31 |
-
result = gen_text[len(p):]
|
32 |
-
# print(">", result)
|
33 |
-
result = my_split(result, [']', '\n'])[1]
|
34 |
-
# print(">>", result)
|
35 |
-
if "Hassan: " in result:
|
36 |
-
result = result.split("Hassan: ")[-1]
|
37 |
-
# print(">>>", result)
|
38 |
-
return result
|
39 |
-
|
40 |
-
import gradio as gr
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
html += f"<div class='user_msg'>{user_msg}</div>"
|
51 |
-
html += f"<div class='resp_msg'>{resp_msg}</div>"
|
52 |
-
html += "</div>"
|
53 |
-
return response
|
54 |
-
|
55 |
-
iface = gr.Interface(chat_base, gr.inputs.Textbox(label="Ask Hassan a Question"), "text", allow_screenshot=False, allow_flagging=False)
|
56 |
-
iface.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
title = "ELECTRA"
|
4 |
+
|
5 |
+
description = "Gradio Demo for ELECTRA. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
|
6 |
+
|
7 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2003.10555' target='_blank'>ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators</a></p>"
|
8 |
+
|
9 |
+
|
10 |
+
examples = [
|
11 |
+
["My name is Sarah and I live in London","electra_large_discriminator_squad2_512","Where do I live?"]
|
12 |
+
]
|
13 |
+
|
14 |
+
io1 = gr.Interface.load("huggingface/ahotrod/electra_large_discriminator_squad2_512")
|
15 |
+
|
16 |
+
io2 = gr.Interface.load("huggingface/deepset/electra-base-squad2")
|
17 |
+
|
18 |
+
def inference(context, model,question):
|
19 |
+
if model == "electra_large_discriminator_squad2_512":
|
20 |
+
outlabel = io1(context,question)
|
21 |
+
else:
|
22 |
+
outlabel = io2(context,question)
|
23 |
+
return outlabel
|
24 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
gr.Interface(
|
27 |
+
inference,
|
28 |
+
[gr.inputs.Textbox(label="Context",lines=10),gr.inputs.Dropdown(choices=["electra_large_discriminator_squad2_512","electra-base-squad2"], type="value", default="electra_large_discriminator_squad2_512", label="model"),gr.inputs.Textbox(label="Question Answering")],
|
29 |
+
[gr.outputs.Textbox(label="Output")],
|
30 |
+
examples=examples,
|
31 |
+
article=article,
|
32 |
+
title=title,
|
33 |
+
description=description).launch(enable_queue=True, cache_examples=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|