Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,48 +2,46 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
title = "
|
| 6 |
-
description = "
|
| 7 |
examples = [["How are you?"]]
|
| 8 |
|
| 9 |
# Set the padding token to be used and initialize the model
|
| 10 |
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
|
| 11 |
tokenizer.padding_side = 'left'
|
| 12 |
-
tokenizer.add_special_tokens({'pad_token': '[EOS]'})
|
| 13 |
-
tokenizer.pad_token = tokenizer.eos_token
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
iface = gr.Interface(
|
| 40 |
-
fn=predict,
|
| 41 |
-
title=title,
|
| 42 |
-
description=description,
|
| 43 |
-
examples=examples,
|
| 44 |
-
inputs=
|
| 45 |
-
outputs=
|
| 46 |
-
theme="ParityError/Anime",
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
-
iface.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
title = "👋🏻Welcome to Tonic's EZ Chat🚀"
|
| 6 |
+
description = "You can use this Space to test out the current model (DialoGPT-medium) or duplicate this Space and use it for anyother model on 🤗HuggingFace."
|
| 7 |
examples = [["How are you?"]]
|
| 8 |
|
| 9 |
# Set the padding token to be used and initialize the model
|
| 10 |
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
|
| 11 |
tokenizer.padding_side = 'left'
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 14 |
+
import gradio as gr
|
| 15 |
+
import torch
|
| 16 |
+
|
| 17 |
+
title = "👋🏻Welcome to Tonic's EZ Chat🚀"
|
| 18 |
+
description = "You can use this Space to test out the current model (DialoGPT-medium) or duplicate this Space and use it for any other model on 🤗HuggingFace. Join me on [Discord](https://discord.gg/fpEPNZGsbt) to build together."
|
| 19 |
+
examples = [["How are you?"]]
|
| 20 |
+
|
| 21 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
|
| 22 |
+
tokenizer.padding_side = 'left'
|
| 23 |
+
|
| 24 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
|
| 25 |
+
|
| 26 |
+
def predict(input, history=[]):
|
| 27 |
+
new_user_input_ids = tokenizer.encode(input, return_tensors="pt")
|
| 28 |
+
|
| 29 |
+
bot_input_ids = torch.cat([torch.tensor(history), new_user_input_ids], dim=-1) if history else new_user_input_ids
|
| 30 |
+
|
| 31 |
+
chat_history_ids = model.generate(bot_input_ids, max_length=4000, pad_token_id=tokenizer.eos_token_id)
|
| 32 |
+
|
| 33 |
+
response = tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)
|
| 34 |
+
|
| 35 |
+
return response
|
| 36 |
+
|
| 37 |
+
iface = gr.Interface(
|
| 38 |
+
fn=predict,
|
| 39 |
+
title=title,
|
| 40 |
+
description=description,
|
| 41 |
+
examples=examples,
|
| 42 |
+
inputs="text",
|
| 43 |
+
outputs="text",
|
| 44 |
+
theme="ParityError/Anime",
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
iface.launch()
|