Update app.py
Browse files
app.py
CHANGED
|
@@ -4,16 +4,14 @@ import gradio as gr
|
|
| 4 |
HF_TOKEN = os.getenv('HF_TOKEN')
|
| 5 |
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "Rick-bot-flags")
|
| 6 |
|
| 7 |
-
title = "
|
| 8 |
description = """
|
| 9 |
-
<p>
|
| 10 |
<center>
|
| 11 |
-
The bot was trained on Rick and Morty dialogues
|
| 12 |
-
|
| 13 |
</center>
|
| 14 |
-
</p>
|
| 15 |
"""
|
| 16 |
-
article = "
|
| 17 |
|
| 18 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 19 |
import torch
|
|
@@ -21,7 +19,7 @@ import torch
|
|
| 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
|
| 25 |
# tokenize the new input sentence
|
| 26 |
new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
| 27 |
|
|
@@ -33,13 +31,6 @@ def predict(input, history=[]):
|
|
| 33 |
|
| 34 |
# convert the tokens to text, and then split the responses into the right format
|
| 35 |
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
| 36 |
-
|
| 37 |
-
return response, history
|
| 38 |
|
| 39 |
-
gr.Interface(fn = predict, inputs = ["textbox"
|
| 40 |
-
|
| 41 |
-
#theme ="grass",
|
| 42 |
-
#title = title,
|
| 43 |
-
#flagging_callback=hf_writer,
|
| 44 |
-
#description = description,
|
| 45 |
-
#article = article
|
|
|
|
| 4 |
HF_TOKEN = os.getenv('HF_TOKEN')
|
| 5 |
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "Rick-bot-flags")
|
| 6 |
|
| 7 |
+
title = "Ask Rick a Question"
|
| 8 |
description = """
|
|
|
|
| 9 |
<center>
|
| 10 |
+
The bot was trained to answer questions based on Rick and Morty dialogues. Ask Rick anything!
|
| 11 |
+

|
| 12 |
</center>
|
|
|
|
| 13 |
"""
|
| 14 |
+
article = "Check out (the original Rick and Morty Bot)[https://huggingface.co/spaces/kingabzpro/Rick_and_Morty_Bot] that this demo is based off of."
|
| 15 |
|
| 16 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 17 |
import torch
|
|
|
|
| 19 |
tokenizer = AutoTokenizer.from_pretrained("ericzhou/DialoGPT-Medium-Rick_v2")
|
| 20 |
model = AutoModelForCausalLM.from_pretrained("ericzhou/DialoGPT-Medium-Rick_v2")
|
| 21 |
|
| 22 |
+
def predict(input):
|
| 23 |
# tokenize the new input sentence
|
| 24 |
new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
| 25 |
|
|
|
|
| 31 |
|
| 32 |
# convert the tokens to text, and then split the responses into the right format
|
| 33 |
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
| 34 |
+
return response[1]
|
|
|
|
| 35 |
|
| 36 |
+
gr.Interface(fn = predict, inputs = ["textbox"], outputs = ["text"],allow_flagging = "manual",title = title, flagging_callback = hf_writer, description = description, article = article ).launch(enable_queue=True) # customizes the input component
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|