Spaces:
Running
Running
Commit
·
b480894
1
Parent(s):
e8a3ed8
Update app.py
Browse files
app.py
CHANGED
@@ -26,20 +26,21 @@ example_contexts = [
|
|
26 |
]
|
27 |
|
28 |
# Function to generate questions and answers with configurable parameters
|
29 |
-
def generate_qa(context, recommended_word, temperature, top_p, num_samples=3):
|
30 |
input_text = f"{recommended_word}: {context}"
|
31 |
-
|
|
|
32 |
|
33 |
# Generate with configurable parameters
|
34 |
output = model.generate(
|
35 |
**input_ids,
|
36 |
temperature=temperature,
|
37 |
top_p=top_p,
|
38 |
-
num_return_sequences=
|
39 |
do_sample=True,
|
40 |
max_length=100,
|
41 |
num_beams=6,
|
42 |
-
length_penalty=1,
|
43 |
top_k=0
|
44 |
)
|
45 |
|
@@ -55,7 +56,9 @@ iface = gr.Interface(
|
|
55 |
gr.inputs.Dropdown(example_contexts, label="Choose an Example"),
|
56 |
gr.inputs.Radio(recommended_words, label="Choose a Recommended Word"),
|
57 |
gr.inputs.Slider(minimum=0.0, maximum=2, default=2.1, step=0.01, label="Temperature"),
|
58 |
-
gr.inputs.Slider(minimum=0.0, maximum=1, default=0.5, step=0.01, label="Top-p")
|
|
|
|
|
59 |
],
|
60 |
outputs=gr.outputs.Textbox(label="Generated Output"),
|
61 |
title="Question Generation and Answering",
|
@@ -63,4 +66,4 @@ iface = gr.Interface(
|
|
63 |
)
|
64 |
|
65 |
# Launch the interface
|
66 |
-
iface.launch(
|
|
|
26 |
]
|
27 |
|
28 |
# Function to generate questions and answers with configurable parameters
|
29 |
+
def generate_qa(context, recommended_word, temperature, top_p,num_seq, num_samples=3):
|
30 |
input_text = f"{recommended_word}: {context}"
|
31 |
+
input_text=re.sub(f'\n'," ",input_text).lower()
|
32 |
+
input_ids = tokenizer(input_text, return_tensors='pt')
|
33 |
|
34 |
# Generate with configurable parameters
|
35 |
output = model.generate(
|
36 |
**input_ids,
|
37 |
temperature=temperature,
|
38 |
top_p=top_p,
|
39 |
+
num_return_sequences=num_seq,
|
40 |
do_sample=True,
|
41 |
max_length=100,
|
42 |
num_beams=6,
|
43 |
+
length_penalty=1.4,
|
44 |
top_k=0
|
45 |
)
|
46 |
|
|
|
56 |
gr.inputs.Dropdown(example_contexts, label="Choose an Example"),
|
57 |
gr.inputs.Radio(recommended_words, label="Choose a Recommended Word"),
|
58 |
gr.inputs.Slider(minimum=0.0, maximum=2, default=2.1, step=0.01, label="Temperature"),
|
59 |
+
gr.inputs.Slider(minimum=0.0, maximum=1, default=0.5, step=0.01, label="Top-p"),
|
60 |
+
gr.inputs.Slider(minimum=1, maximum=20, default=3, step=1, label="num of sequance")
|
61 |
+
|
62 |
],
|
63 |
outputs=gr.outputs.Textbox(label="Generated Output"),
|
64 |
title="Question Generation and Answering",
|
|
|
66 |
)
|
67 |
|
68 |
# Launch the interface
|
69 |
+
iface.launch()
|