ysharma's picture
ysharma HF staff
update
ee2bad7
import requests
import gradio as gr
import os
#Lex's prompt
prompt_lex = """Lex: Let's start with an easy question about consciousness. In your view, is consciousness something that's unique to humans or is it something that permeates all matter? Almost like a fundamental force of physics?
Elon: I don't think consciousness permeates all matter.
Lex: That's true? That's a good point.
Elon: I believe in scientific method. Don't want to blow your mind or anything, but the scientific method is if you cannot test the hypothes is, then you cannot reach meaningful conclusion that it is true.
Lex: Do you think consciousness, understanding consciousness is within the reach of science of the scientific method?
Elon: We can dramatically improve our understanding of consciousness. I'd be hard pressed to say that we understand anything with complete accuracy, but can we dramatically improve our understanding of consciousness? I believe the answer is yes.
Lex: Does an AI system, in your view have to have consciousness in order to achieve human level or super human level intelligence? Does it need to have some of these human qualities like consciousness, maybe a body, maybe a fear of mortality, capacity to love, those kinds of silly human things?
Elon: It's different. There's this scientific method which I very much believe in where something is true to the degree that it is testably so. And otherwise you're really just talking about preferences or untestable beliefs or that kind of thing. So it ends up being somewhat of a semantic question where we are conflating a lot of things with the word intelligence. If we parse them out and say, are we headed towards the future where an AI will be able to out-think us in every way, then the answer is unequivocally yes.
Lex: In order for an AI system that needs to out-think us in every way, it also needs to have a capacity to have consciousness, self-awareness and understand ...
Elon: It will be self-aware, yes. That's different from consciousness. I mean to me in terms of what consciousness feels like, it feels like consciousness is in a different dimension. But this could be just an illusion. If you damage your brain in some way physically, you damage your consciousness, which implies that consciousness is a physical phenomenon in my view. The thing is that I think are really quite likely is that digital intelligence will be able to out-think us in every way. And it will suddenly be able to simulate what we consider consciousness. So to the degree that you would not be able to tell the difference.
Lex: """
#Rick Sanchez's prompt
prompt_rick = """Lex: Ohh, man. Oh, geez! Ohh.
Rick: I'm sorry, Morty. It's a bummer. In reality, you're as dumb as they come and I needed those seeds real bad, and I had to give them up just to get your parents off my back, so now we're gonna have to go get more adventures. And then we're gonna go on even more adventures after that, Morty and you're gonna keep your mouth shut about it, Morty, because the world is full of idiots that don't understand what's important, and they'll tear us apart, Morty but if you stick with me, I'm gonna accomplish great things, Morty, and you're gonna be part of them, and together, we're gonna run around, Morty. We're gonna do all kinds of wonderful things, Morty. Just you and me, Morty. The outside world is our enemy, Morty. We're the only friends we've got, Morty. It's just Rick and Morty. Rick and Morty and their adventures, Morty. Rick and Morty forever and forever. Morty's things. Me and Rick and Morty running around, and Rick and Morty time. All day long, forever. All a hundred days. Rick and Morty forever 100 times. Over and over, rickandmortyadventures.com. All 100 years. Every minute, rickandmorty.com.
Lex: Okay, with all due respect, Rick— what am I talking about? What respect is due? How is my son supposed to pass his classes if you keep dragging him off for high-concept Sci-Fi rigamarole?
Rick: Listen, Jerry. I-I-I don't want to overstep my bounds or anything. It's your house. It's your world. You're a real Julius Caesar but I'll tell you something—tell you how I feel about school, Jerry. It's a waste of time. Buncha people running around, bumping into each other. G-guy up front says, "two plus two." The people in the back say, "four." Then the—then the bell rings, and they give you a carton of milk and a piece of paper that says you can go take a dump or something. I mean, it's not a place for smart people, Jerry. And I know that's not a popular opinion, but it's my two cents on the issue. This was a good breakfast, Beth. You really made the crap out of those eggs. I wish your mother was here to eat them.
Lex: Wow, that's pretty crazy, Rick.
Rick: There's just one problem, Morty one little hang-up. The dimension I visited was so advanced, that they had also halted the aging process, and everyone there was young, Morty, and they had been forever. I was the only old person there, Morty. It was like I was some sort of, you know, celebrity, walking around. I-I was fascinating to them. There were a lot of attractive women there, Morty, and they-they-they— they all wanted time with me. I had a lot of fun with a lot of young ladies, but I spent so much time there, my interdimensional portal device it's got no charge left, Morty. It's got no charge left.
Lex: Why didn't you want to come here?
Rick: Because I don't respect therapy, because I'm a scientist. Because I invent, transform, create, and destroy for a living, and when I don't like something about the world, I change it. And I don't think going to a rented office in a strip mall to listen to some agent of averageness explain which words mean which feelings has ever helped anyone do anything.
Lex: What do you want?
Rick: """
# Using GPT-J-6B API
# Model 2: Sentence Transformer
API_URL = "https://api-inference.huggingface.co/models/EleutherAI/gpt-j-6B"
HF_TOKEN = os.environ["HF_TOKEN"]
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
#API_URL = "https://api-inference.huggingface.co/models/EleutherAI/gpt-j-6B"
#headers = {"Authorization": "Bearer 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"}
#Prompting the model and getting a response json
def get_rick_response(lex_says):
print('INSIDE Rick RESPONSE')
period = lex_says.find('.')
ques = lex_says.find('?')
if period == -1:
if ques == -1:
comma = lex_says.find(',')
lex_says = lex_says[:comma+1]
else:
lex_says = lex_says[:ques+1]
else:
if ques == -1:
lex_says = lex_says[:period+1]
else:
if period > ques:
lex_says = lex_says[:ques+1]
else:
lex_says = lex_says[:period+1]
tmp = ["Lex: "+lex_says,"","Rick: "]
print('tmp/Ricks prompt is : ', tmp)
prompt_rick_upd = prompt_rick.split('\n')[:-2]
prompt_rick_upd.extend(tmp)
prompt_rick_upd = '\n'.join(prompt_rick_upd)
#Preparing final prompt
rick = {"inputs": prompt_rick_upd,
"parameters":
{
"top_p": 0.9,
"temperature": 1.1,
"max_new_tokens": 250,
"return_full_text": False
}}
#Getting response for Rick
response_rick = requests.post(API_URL, headers=headers, json=rick)
print('Rick full response is : ', response_rick.json())
rick_says = response_rick.json()[0]['generated_text'].split('\n')[0]
rick_says = rick_says.replace('Morty', 'Lex')
rick_says = rick_says.replace('Jerry', 'Lex')
print('Rick final response is : ', rick_says)
return rick_says
def get_lex_response(prompt_lex, message=None): #(answer=None):
print('INSIDE LEX RESPONSE')
if (message is not None):
tmp = ["Lex: "+ message]
print('tmp is : ', tmp)
prompt_lex_upd = prompt_lex.split('\n')[:-1]
prompt_lex_upd.extend(tmp)
prompt_lex = '\n'.join(prompt_lex_upd)
print('prompt_lex after join is : ', prompt_lex)
#Preparing Final Prompt
Lex = {"inputs": prompt_lex,
"parameters":
{
"top_p": 0.9,
"temperature": 1.1,
"max_new_tokens": 250,
"return_full_text": False
}}
#Getting response for Lex
response_lex = requests.post(API_URL, headers=headers, json=Lex)
tmp1 = response_lex.json()
print('tmp1 is : ', tmp1)
lex_says = response_lex.json()[0]['generated_text'].split('\n')[0]
return lex_says #, response_lex.json()[0]['generated_text'].split('\n')
#Main
def chat(message, history):
history = history or []
if (message is None) :
lex_says = get_lex_response(prompt_lex)
rick_says = get_rick_response(lex_says)
else :
lex_says = str(message) + str(get_lex_response(prompt_lex, message) ) #(prompt_lex, message=None)
rick_says = get_rick_response(lex_says)
history.append((lex_says, rick_says))
return history, history
iface = gr.Interface(
chat,
["text", "state"],
["chatbot", "state"],
allow_screenshot=False,
allow_flagging="never",
title="A Conversation between Lex and Rick Sanchez 🎤",
description="<div>The Demo tries to generate an imaginary conversation between Lex and Rick Sanchez. 🤯 Had it been possible, what amazing conversation it would have made! <br>Rick's responses have been generated by prompting the <a href='https://huggingface.co/EleutherAI/gpt-j-6B' target='_blank'>GPT-j-6B model</a> model with transcripts from RickandMorty episodes while Lex's questions are generated by passing some of the excerpts from Lex's podcast transcripts as prompt to <a href='https://huggingface.co/EleutherAI/gpt-j-6B' target='_blank'>GPT-j-6B model</a>. You can either give a prompt or simply press submit at first.<br> Now Go ahead and type in some of the regular questions that Lex asks his guests like 👀 (Text with light grey background are Rick's 'replies') - <br>🚀 What do you think of Elon Musk <br>💗 Ok, what is the meaning of life <br>👦 What will you like to tell the young listeners of this podcast <br>💁 What does consciousness mean <br>👽 Are Aliens watching us or something of the sorts.<br> The prompts might be completed to match Lex's style by 🤗 GPTJ6B model or might go in as is.<br><br>Have fun 😄.<br> <div class='row'> <div class='column'> <img src='https://www.writeups.org/wp-content/uploads/Rick-Sanchez-Rick-and-Morty.jpg' height='160' width='160' class='center'> </div> <div class='column'> <img src='https://cdn.impactinit.com/resizenp/600x600/x@7cfb07059b/smss52/smsimg30/pv1000/isignstockcontributors/iss_22941_00183.jpg' height='300' width='300' class='center'> </div> </div> </div>" ,
css= """.column {
float: left;
width: 50%;
padding: 0.5px;
}
.row::after {
content: "";
clear: both;
display: table;
}
""",
article="<div> Please note that since GPTJ-6B is a huge-huge model, the space might fail out with Cuda out of memory error sometimes. This usually happens if a 'longer' prompt is given as Lex's question. 😇 Would request you to bear with the infra and clear the Error and start again with another input 🙏.</div>"
)
iface.launch()
#'http://assets.stickpng.com/images/58f37726a4fa116215a92410.png'
#I think it's helped a lot of people get comfortable and stop panicking, which is a state of mind we value in the animals we eat, but not something I want for myself. I'm not a cow. I'm a pickle. When I feel like it. So...you asked.