Spaces:
Runtime error
Runtime error
Commit
·
be3cef5
1
Parent(s):
0e67816
testing multiple
Browse files
app.py
CHANGED
@@ -1,49 +1,60 @@
|
|
1 |
-
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
The bot was trained on Rick and Morty dialogues Kaggle Dataset using DialoGPT.
|
12 |
-
<img src="https://huggingface.co/spaces/kingabzpro/Rick_and_Morty_Bot/resolve/main/img/rick.png" alt="rick" width="200"/>
|
13 |
-
</center>
|
14 |
-
</p>
|
15 |
-
"""
|
16 |
-
article = "<p style='text-align: center'><a href='https://medium.com/geekculture/discord-bot-using-dailogpt-and-huggingface-api-c71983422701' target='_blank'>Complete Tutorial</a></p><p style='text-align: center'><a href='https://dagshub.com/kingabzpro/DailoGPT-RickBot' target='_blank'>Project is Available at DAGsHub</a></p></center><center><img src='https://visitor-badge.glitch.me/badge?page_id=kingabzpro/Rick_and_Morty_Bot' alt='visitor badge'></center></p>"
|
17 |
-
examples = [["How are you Rick?"]]
|
18 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
19 |
-
import torch
|
20 |
-
|
21 |
-
tokenizer = AutoTokenizer.from_pretrained("ericzhou/DialoGPT-Medium-Rick_v2")
|
22 |
-
model = AutoModelForCausalLM.from_pretrained("ericzhou/DialoGPT-Medium-Rick_v2")
|
23 |
-
|
24 |
-
def predict(input, history=[]):
|
25 |
-
# tokenize the new input sentence
|
26 |
-
new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
27 |
-
|
28 |
-
# append the new user input tokens to the chat history
|
29 |
-
bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
30 |
-
|
31 |
-
# generate a response
|
32 |
-
history = model.generate(bot_input_ids, max_length=4000, pad_token_id=tokenizer.eos_token_id).tolist()
|
33 |
-
|
34 |
-
# convert the tokens to text, and then split the responses into lines
|
35 |
-
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
36 |
-
#print('decoded_response-->>'+str(response))
|
37 |
-
response = [(response[i], response[i+1]) for i in range(0, len(response)-1, 2)] # convert to tuples of list
|
38 |
-
#print('response-->>'+str(response))
|
39 |
-
return response, history
|
40 |
-
|
41 |
-
gr.Interface(fn=predict,
|
42 |
-
title=title,
|
43 |
-
description=description,
|
44 |
-
examples=examples,
|
45 |
-
flagging_callback = hf_writer,
|
46 |
-
allow_flagging = "manual",
|
47 |
-
inputs=["text", "state"],
|
48 |
-
outputs=["chatbot", "state"],
|
49 |
-
theme='gradio/seafoam').launch()
|
|
|
1 |
+
# import os
|
2 |
+
# import gradio as gr
|
3 |
+
|
4 |
+
# HF_TOKEN = os.getenv('HF_TOKEN')
|
5 |
+
# hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "Rick-bot-flags")
|
6 |
+
|
7 |
+
# title = "Talk To Me Morty"
|
8 |
+
# description = """
|
9 |
+
# <p>
|
10 |
+
# <center>
|
11 |
+
# The bot was trained on Rick and Morty dialogues Kaggle Dataset using DialoGPT.
|
12 |
+
# <img src="https://huggingface.co/spaces/kingabzpro/Rick_and_Morty_Bot/resolve/main/img/rick.png" alt="rick" width="200"/>
|
13 |
+
# </center>
|
14 |
+
# </p>
|
15 |
+
# """
|
16 |
+
# article = "<p style='text-align: center'><a href='https://medium.com/geekculture/discord-bot-using-dailogpt-and-huggingface-api-c71983422701' target='_blank'>Complete Tutorial</a></p><p style='text-align: center'><a href='https://dagshub.com/kingabzpro/DailoGPT-RickBot' target='_blank'>Project is Available at DAGsHub</a></p></center><center><img src='https://visitor-badge.glitch.me/badge?page_id=kingabzpro/Rick_and_Morty_Bot' alt='visitor badge'></center></p>"
|
17 |
+
# examples = [["How are you Rick?"]]
|
18 |
+
# from transformers import AutoModelForCausalLM, AutoTokenizer
|
19 |
+
# import torch
|
20 |
+
|
21 |
+
# tokenizer = AutoTokenizer.from_pretrained("ericzhou/DialoGPT-Medium-Rick_v2")
|
22 |
+
# model = AutoModelForCausalLM.from_pretrained("ericzhou/DialoGPT-Medium-Rick_v2")
|
23 |
+
|
24 |
+
# def predict(input, history=[]):
|
25 |
+
# # tokenize the new input sentence
|
26 |
+
# new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
27 |
+
|
28 |
+
# # append the new user input tokens to the chat history
|
29 |
+
# bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
30 |
+
|
31 |
+
# # generate a response
|
32 |
+
# history = model.generate(bot_input_ids, max_length=4000, pad_token_id=tokenizer.eos_token_id).tolist()
|
33 |
+
|
34 |
+
# # convert the tokens to text, and then split the responses into lines
|
35 |
+
# response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
36 |
+
# #print('decoded_response-->>'+str(response))
|
37 |
+
# response = [(response[i], response[i+1]) for i in range(0, len(response)-1, 2)] # convert to tuples of list
|
38 |
+
# #print('response-->>'+str(response))
|
39 |
+
# return response, history
|
40 |
+
|
41 |
+
# gr.Interface(fn=predict,
|
42 |
+
# title=title,
|
43 |
+
# description=description,
|
44 |
+
# examples=examples,
|
45 |
+
# flagging_callback = hf_writer,
|
46 |
+
# allow_flagging = "manual",
|
47 |
+
# inputs=["text", "state"],
|
48 |
+
# outputs=["chatbot", "state"],
|
49 |
+
# theme='gradio/seafoam').launch()
|
50 |
+
|
51 |
+
|
52 |
import gradio as gr
|
53 |
|
54 |
+
with gr.Blocks() as demo:
|
55 |
+
with gr.Tab("Translate to Spanish"):
|
56 |
+
gr.load("gradio/en2es", src="spaces")
|
57 |
+
with gr.Tab("Translate to French"):
|
58 |
+
gr.load("abidlabs/en2fr", src="spaces")
|
59 |
+
|
60 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|