paramasivan27
commited on
Commit
•
9051bc2
1
Parent(s):
5577cf9
Update space
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ model_name = "paramasivan27/gpt2_for_q_and_a"
|
|
8 |
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
9 |
model = GPT2LMHeadModel.from_pretrained(model_name)
|
10 |
|
11 |
-
def ask_question(question):
|
12 |
inputs = tokenizer.encode('Q: ' + question + ' A:', return_tensors='pt')
|
13 |
attention_mask = torch.ones(inputs.shape)
|
14 |
outputs = model.generate(inputs, attention_mask = attention_mask, max_new_tokens=100, num_return_sequences=1)
|
@@ -19,19 +19,7 @@ def ask_question(question):
|
|
19 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
20 |
"""
|
21 |
demo = gr.ChatInterface(
|
22 |
-
ask_question
|
23 |
-
additional_inputs=[
|
24 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
25 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
26 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
27 |
-
gr.Slider(
|
28 |
-
minimum=0.1,
|
29 |
-
maximum=1.0,
|
30 |
-
value=0.95,
|
31 |
-
step=0.05,
|
32 |
-
label="Top-p (nucleus sampling)",
|
33 |
-
),
|
34 |
-
],
|
35 |
)
|
36 |
|
37 |
|
|
|
8 |
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
9 |
model = GPT2LMHeadModel.from_pretrained(model_name)
|
10 |
|
11 |
+
def ask_question(question, m_tokens):
|
12 |
inputs = tokenizer.encode('Q: ' + question + ' A:', return_tensors='pt')
|
13 |
attention_mask = torch.ones(inputs.shape)
|
14 |
outputs = model.generate(inputs, attention_mask = attention_mask, max_new_tokens=100, num_return_sequences=1)
|
|
|
19 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
20 |
"""
|
21 |
demo = gr.ChatInterface(
|
22 |
+
ask_question
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
)
|
24 |
|
25 |
|