Spaces:
Runtime error
Runtime error
deepapaikar
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,7 @@ pipeline = transformers.pipeline(
|
|
19 |
tokenizer = AutoTokenizer.from_pretrained(model)
|
20 |
|
21 |
|
22 |
-
def predict_answer(question):
|
23 |
|
24 |
messages = [{"role": "user", "content": f"{question}"}]
|
25 |
|
@@ -27,20 +27,21 @@ def predict_answer(question):
|
|
27 |
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
28 |
|
29 |
|
30 |
-
outputs = pipeline(prompt, max_new_tokens=
|
31 |
|
32 |
return outputs[0]["generated_text"]
|
33 |
|
34 |
|
35 |
|
36 |
-
def gradio_predict(question):
|
37 |
-
answer = predict_answer(question)
|
38 |
return answer
|
39 |
|
40 |
# Define the Gradio interface
|
41 |
iface = gr.Interface(
|
42 |
fn=gradio_predict,
|
43 |
-
inputs=[gr.Textbox(label="Question", placeholder="e.g. What are the colors of the bus in the image?", scale=4)
|
|
|
44 |
outputs=gr.TextArea(label="Answer"),
|
45 |
title="KatzBot",
|
46 |
description="Llama - Mistral Merge",
|
|
|
19 |
tokenizer = AutoTokenizer.from_pretrained(model)
|
20 |
|
21 |
|
22 |
+
def predict_answer(question, token=25):
|
23 |
|
24 |
messages = [{"role": "user", "content": f"{question}"}]
|
25 |
|
|
|
27 |
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
28 |
|
29 |
|
30 |
+
outputs = pipeline(prompt, max_new_tokens=token, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
31 |
|
32 |
return outputs[0]["generated_text"]
|
33 |
|
34 |
|
35 |
|
36 |
+
def gradio_predict(question, token):
|
37 |
+
answer = predict_answer(question, token)
|
38 |
return answer
|
39 |
|
40 |
# Define the Gradio interface
|
41 |
iface = gr.Interface(
|
42 |
fn=gradio_predict,
|
43 |
+
inputs=[gr.Textbox(label="Question", placeholder="e.g. What are the colors of the bus in the image?", scale=4),
|
44 |
+
gr.Slider(2, 100, value=25, label="Token Count", info="Choose between 2 and 100")]],
|
45 |
outputs=gr.TextArea(label="Answer"),
|
46 |
title="KatzBot",
|
47 |
description="Llama - Mistral Merge",
|