Spaces:
Sleeping
Sleeping
mrolando
commited on
Commit
·
9f9f985
1
Parent(s):
19390d5
added option to select person
Browse files
app.py
CHANGED
|
@@ -18,9 +18,11 @@ openai.api_key = os.environ['OPENAI_API_KEY']
|
|
| 18 |
def clear_chat(message, chat_history):
|
| 19 |
return "", []
|
| 20 |
|
| 21 |
-
def add_new_message(message,chat_history):
|
| 22 |
new_chat = []
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
for turn in chat_history:
|
| 25 |
user, bot = turn
|
| 26 |
new_chat.append({"role": "user", "content": user})
|
|
@@ -30,8 +32,8 @@ def add_new_message(message,chat_history):
|
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
-
def respond(message, chat_history):
|
| 34 |
-
prompt = add_new_message(message, chat_history)
|
| 35 |
# stream = client.generate_stream(prompt,
|
| 36 |
# max_new_tokens=1024,
|
| 37 |
# stop_sequences=["\nUser:", "<|endoftext|>"],
|
|
@@ -77,12 +79,14 @@ with gr.Blocks() as demo:
|
|
| 77 |
</h1>
|
| 78 |
<img src='data:image/jpg;base64,{}' width=200px>
|
| 79 |
<h3>
|
| 80 |
-
Con este espacio podrás hablar en formato conversación con Albert Einstein!
|
| 81 |
</h3>
|
| 82 |
</center>
|
| 83 |
""".format(encoded_image))
|
| 84 |
with gr.Row():
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
with gr.Row():
|
| 87 |
with gr.Row():
|
| 88 |
with gr.Column(scale=4):
|
|
@@ -94,8 +98,8 @@ with gr.Blocks() as demo:
|
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
-
btn.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 98 |
-
msg.submit(respond, inputs=[msg, chatbot], outputs=[msg, chatbot]) #Press enter to submit
|
| 99 |
clear.click(clear_chat,inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 100 |
demo.queue()
|
| 101 |
demo.launch()
|
|
|
|
| 18 |
def clear_chat(message, chat_history):
|
| 19 |
return "", []
|
| 20 |
|
| 21 |
+
def add_new_message(message,person, chat_history):
|
| 22 |
new_chat = []
|
| 23 |
+
|
| 24 |
+
new_chat.append({"role": "system", "content": 'Sos {} y tendrás que responder preguntas que te harán niños de escuela, las respuestas tienen que ser cómo si hablaras con {} y con la información de su vida. Las respuestas tienen que estar orientadas a niños entre 9 y 10 años.'.format(person,person)})
|
| 25 |
+
|
| 26 |
for turn in chat_history:
|
| 27 |
user, bot = turn
|
| 28 |
new_chat.append({"role": "user", "content": user})
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
+
def respond(message, person, chat_history):
|
| 36 |
+
prompt = add_new_message(message, person, chat_history)
|
| 37 |
# stream = client.generate_stream(prompt,
|
| 38 |
# max_new_tokens=1024,
|
| 39 |
# stop_sequences=["\nUser:", "<|endoftext|>"],
|
|
|
|
| 79 |
</h1>
|
| 80 |
<img src='data:image/jpg;base64,{}' width=200px>
|
| 81 |
<h3>
|
| 82 |
+
Con este espacio podrás hablar en formato conversación con el personaje famoso que quieras, puede ser Albert Einstein, Marie Curie o el/la que quieras!
|
| 83 |
</h3>
|
| 84 |
</center>
|
| 85 |
""".format(encoded_image))
|
| 86 |
with gr.Row():
|
| 87 |
+
person = gr.Textbox(label="Escribí el nombre del perosnaje famoso:")
|
| 88 |
+
with gr.Row():
|
| 89 |
+
chatbot = gr.Chatbot( height=550) #just to fit the notebook
|
| 90 |
with gr.Row():
|
| 91 |
with gr.Row():
|
| 92 |
with gr.Column(scale=4):
|
|
|
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
+
btn.click(respond, inputs=[msg,person, chatbot], outputs=[msg, chatbot])
|
| 102 |
+
msg.submit(respond, inputs=[msg, person,chatbot], outputs=[msg, chatbot]) #Press enter to submit
|
| 103 |
clear.click(clear_chat,inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 104 |
demo.queue()
|
| 105 |
demo.launch()
|