Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
|
| 5 |
model_path = "Wonder-Griffin/ShorseyBeerLeague"
|
|
@@ -11,13 +10,9 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 11 |
torch_dtype='auto'
|
| 12 |
).eval()
|
| 13 |
|
| 14 |
-
input_ids = tokenizer.apply_chat_template(conversation=messages, tokenize=True, add_generation_prompt=True, return_tensors='pt')
|
| 15 |
-
output_ids = model.generate(input_ids.to('cuda'))
|
| 16 |
-
respond = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
|
| 17 |
-
|
| 18 |
def respond(
|
| 19 |
message,
|
| 20 |
-
history
|
| 21 |
system_message,
|
| 22 |
max_tokens,
|
| 23 |
temperature,
|
|
@@ -33,19 +28,11 @@ def respond(
|
|
| 33 |
|
| 34 |
messages.append({"role": "user", "content": message})
|
| 35 |
|
|
|
|
|
|
|
| 36 |
respond = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
messages,
|
| 40 |
-
max_tokens=max_tokens,
|
| 41 |
-
stream=True,
|
| 42 |
-
temperature=temperature,
|
| 43 |
-
top_p=top_p,
|
| 44 |
-
):
|
| 45 |
-
token = message.choices[0].delta.content
|
| 46 |
-
|
| 47 |
-
respond += token
|
| 48 |
-
yield respond
|
| 49 |
|
| 50 |
"""
|
| 51 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
@@ -64,8 +51,4 @@ demo = gr.ChatInterface(
|
|
| 64 |
label="Top-p (nucleus sampling)",
|
| 65 |
),
|
| 66 |
],
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
if __name__ == "__main__":
|
| 71 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
|
| 4 |
model_path = "Wonder-Griffin/ShorseyBeerLeague"
|
|
|
|
| 10 |
torch_dtype='auto'
|
| 11 |
).eval()
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def respond(
|
| 14 |
message,
|
| 15 |
+
history,
|
| 16 |
system_message,
|
| 17 |
max_tokens,
|
| 18 |
temperature,
|
|
|
|
| 28 |
|
| 29 |
messages.append({"role": "user", "content": message})
|
| 30 |
|
| 31 |
+
input_ids = tokenizer.apply_chat_template(conversation=messages, tokenize=True, add_generation_prompt=True, return_tensors='pt')
|
| 32 |
+
output_ids = model.generate(input_ids.to('cuda'))
|
| 33 |
respond = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
|
| 34 |
|
| 35 |
+
return respond
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
"""
|
| 38 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
|
| 51 |
label="Top-p (nucleus sampling)",
|
| 52 |
),
|
| 53 |
],
|
| 54 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|