abidlabs HF staff commited on
Commit
1b950dc
·
1 Parent(s): fb17113

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -16
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 = "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></p>"
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, history=[]):
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
- response = [(response[i], response[i+1]) for i in range(0, len(response)-1, 2)] # convert to tuples of list
37
- return response, history
38
 
39
- gr.Interface(fn = predict, inputs = ["textbox","state"], outputs = ["chatbot","state"],allow_flagging = "manual",title = title, flagging_callback = hf_writer, description = description, article = article ).launch(enable_queue=True) # customizes the input component
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
+ ![](rick.png)
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