|
import gradio as gr |
|
import openai |
|
|
|
|
|
openai.api_key = "" |
|
|
|
|
|
def chat_with_figure(figure, message): |
|
prompt = f"You are chatting with {figure}.\n\nUser: {message}\n{figure}:" |
|
response = openai.Completion.create( |
|
engine="text-davinci-003", |
|
prompt=prompt, |
|
max_tokens=150, |
|
temperature=0.6, |
|
top_p=0.9, |
|
frequency_penalty=0.0, |
|
presence_penalty=0.6, |
|
n=1, |
|
stop=None |
|
) |
|
reply = response.choices[0].text.strip().split("\n")[0] |
|
return reply |
|
|
|
|
|
def chat_interface(figure, message): |
|
reply = chat_with_figure(figure, message) |
|
return f"{figure}: {reply}" |
|
|
|
figure_input = gr.inputs.Textbox(label="Enter the name of the influential figure") |
|
message_input = gr.inputs.Textbox(label="Chat message") |
|
output_text = gr.outputs.Textbox() |
|
|
|
iface = gr.Interface( |
|
fn=chat_interface, |
|
inputs=[figure_input, message_input], |
|
outputs=output_text, |
|
title="Chat with an Influential Figure", |
|
description="Enter the name of an influential figure and start a conversation.", |
|
examples=[ |
|
["Albert Einstein", "What is the meaning of life?"], |
|
["Oprah Winfrey", "How can I achieve my goals?"], |
|
["Steve Jobs", "Tell me about your journey in technology."] |
|
] |
|
) |
|
|
|
|
|
iface.launch() |
|
|