Spaces:
Running
Running
Commit
·
a643b2a
1
Parent(s):
7948429
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ recommended_words = [
|
|
18 |
]
|
19 |
|
20 |
# Function to generate questions and answers with configurable parameters
|
21 |
-
def generate_qa(context, recommended_word, temperature, top_p):
|
22 |
input_text = f"{recommended_word}: {context.lower()}"
|
23 |
input_ids = tokenizer(input_text, max_length=400, truncation=True, padding="max_length", return_tensors='pt')
|
24 |
|
@@ -26,7 +26,7 @@ def generate_qa(context, recommended_word, temperature, top_p):
|
|
26 |
output = model.generate(
|
27 |
**input_ids,
|
28 |
temperature=temperature,
|
29 |
-
top_p=top_p
|
30 |
)
|
31 |
|
32 |
generated_text = tokenizer.batch_decode(output, skip_special_tokens=True)
|
@@ -37,14 +37,17 @@ iface = gr.Interface(
|
|
37 |
fn=generate_qa,
|
38 |
inputs=[
|
39 |
"text",
|
40 |
-
gr.inputs.
|
41 |
-
gr.inputs.Slider(minimum=0, maximum=4, default=
|
42 |
-
gr.inputs.Slider(minimum=0.1, maximum=1, default=0.2, step=0.
|
|
|
|
|
43 |
],
|
44 |
outputs="text",
|
45 |
title="Question Generation and Answering",
|
46 |
description="Enter a context, choose a recommended word, and adjust temperature and top-p. The model will generate a question and answer.",
|
47 |
)
|
48 |
|
|
|
49 |
# Launch the interface
|
50 |
iface.launch()
|
|
|
18 |
]
|
19 |
|
20 |
# Function to generate questions and answers with configurable parameters
|
21 |
+
def generate_qa(context, recommended_word, temperature, top_p,numofseq):
|
22 |
input_text = f"{recommended_word}: {context.lower()}"
|
23 |
input_ids = tokenizer(input_text, max_length=400, truncation=True, padding="max_length", return_tensors='pt')
|
24 |
|
|
|
26 |
output = model.generate(
|
27 |
**input_ids,
|
28 |
temperature=temperature,
|
29 |
+
top_p=top_p,num_return_sequences=numofseq
|
30 |
)
|
31 |
|
32 |
generated_text = tokenizer.batch_decode(output, skip_special_tokens=True)
|
|
|
37 |
fn=generate_qa,
|
38 |
inputs=[
|
39 |
"text",
|
40 |
+
gr.inputs.Radio(recommended_words, label="Choose a Recommended Word"),
|
41 |
+
gr.inputs.Slider(minimum=0, maximum=4, default=1, step=0.05, label="Temperature"),
|
42 |
+
gr.inputs.Slider(minimum=0.1, maximum=1, default=0.2, step=0.05, label="Top-p"),
|
43 |
+
gr.inputs.Slider(minimum=1, maximum=50, default=1, step=1, label="num_return_sequences")
|
44 |
+
|
45 |
],
|
46 |
outputs="text",
|
47 |
title="Question Generation and Answering",
|
48 |
description="Enter a context, choose a recommended word, and adjust temperature and top-p. The model will generate a question and answer.",
|
49 |
)
|
50 |
|
51 |
+
|
52 |
# Launch the interface
|
53 |
iface.launch()
|