Created
December 15, 2023 18:40
-
-
Save rohitrajiit/2fe090457750cbc026e46e8c60d28d6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gradio as gr | |
import google.generativeai as genai | |
apikey = 'xxx' # Replace with your key | |
genai.configure(api_key=apikey) | |
with gr.Blocks() as demo: | |
chatbot = gr.Chatbot() | |
msg = gr.Textbox() | |
clear = gr.ClearButton([msg, chatbot]) | |
model = genai.GenerativeModel('gemini-pro') | |
def respond(message, chat_history): | |
history_gemini_format = [] | |
for user, assistant in chat_history: | |
history_gemini_format.append({'role':'user', | |
'parts':[user]}) | |
history_gemini_format.append({'role':'model', | |
'parts':[assistant]}) | |
history_gemini_format.append({'role':'user', | |
'parts':[message]}) | |
print(history_gemini_format) | |
response = model.generate_content(history_gemini_format) | |
responsetext = response.text | |
chat_history.append((message, responsetext)) | |
return "", chat_history | |
msg.submit(respond, [msg, chatbot], [msg, chatbot]) | |
demo.launch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment