Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -51,11 +51,6 @@ def generate(
|
|
51 |
conversation.append({"role": "user", "content": message})
|
52 |
|
53 |
input_text = "\n".join([f"{entry['role']}: {entry['content']}" for entry in conversation])
|
54 |
-
inputs = tokenizer(input_text, return_tensors="pt")
|
55 |
-
if inputs.input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
56 |
-
inputs = {k: v[:, -MAX_INPUT_TOKEN_LENGTH:] for k, v in inputs.items()}
|
57 |
-
gr.Warning(f"Trimmed input from conversation as it was longer than {MAX_INPUT_TOKEN_LENGTH} tokens.")
|
58 |
-
inputs = inputs.to(pipe.device)
|
59 |
|
60 |
generate_kwargs = {
|
61 |
"max_new_tokens": max_new_tokens,
|
@@ -67,7 +62,7 @@ def generate(
|
|
67 |
}
|
68 |
|
69 |
def run_generation():
|
70 |
-
return pipe(
|
71 |
|
72 |
t = Thread(target=run_generation)
|
73 |
t.start()
|
@@ -119,9 +114,10 @@ chat_interface = gr.ChatInterface(
|
|
119 |
],
|
120 |
stop_btn=None,
|
121 |
examples=[
|
122 |
-
["
|
123 |
-
["
|
124 |
-
["
|
|
|
125 |
["Write a 100-word article on 'Benefits of Open-Source in AI research'"],
|
126 |
],
|
127 |
)
|
@@ -133,4 +129,4 @@ with gr.Blocks(css="style.css") as demo:
|
|
133 |
gr.Markdown(LICENSE)
|
134 |
|
135 |
if __name__ == "__main__":
|
136 |
-
demo.queue(max_size=20).launch()
|
|
|
51 |
conversation.append({"role": "user", "content": message})
|
52 |
|
53 |
input_text = "\n".join([f"{entry['role']}: {entry['content']}" for entry in conversation])
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
generate_kwargs = {
|
56 |
"max_new_tokens": max_new_tokens,
|
|
|
62 |
}
|
63 |
|
64 |
def run_generation():
|
65 |
+
return pipe(input_text, **generate_kwargs)
|
66 |
|
67 |
t = Thread(target=run_generation)
|
68 |
t.start()
|
|
|
114 |
],
|
115 |
stop_btn=None,
|
116 |
examples=[
|
117 |
+
["Hello there! How are you doing?"],
|
118 |
+
["Can you explain briefly to me what is the Python programming language?"],
|
119 |
+
["Explain the plot of Cinderella in a sentence."],
|
120 |
+
["How many hours does it take a man to eat a Helicopter?"],
|
121 |
["Write a 100-word article on 'Benefits of Open-Source in AI research'"],
|
122 |
],
|
123 |
)
|
|
|
129 |
gr.Markdown(LICENSE)
|
130 |
|
131 |
if __name__ == "__main__":
|
132 |
+
demo.queue(max_size=20).launch()
|