anji19 commited on
Commit
94dd525
·
verified ·
1 Parent(s): 0f13c12

Upload 2 files

Browse files
Files changed (2) hide show
  1. .env +1 -0
  2. geminiAPIv2.py +29 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY="AIzaSyBaMtbGoJFN2YfDqCOYlsw8S6RO_VISq18"
geminiAPIv2.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+
4
+ import os
5
+ import google.generativeai as genai
6
+ import gradio as gr
7
+
8
+ # Configure Google Generative AI
9
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
10
+ model = genai.GenerativeModel("gemini-pro")
11
+
12
+ def get_gemini_responces(message, chat_history):
13
+ # Assuming the message is a question for the Gemini model
14
+ responce = model.generate_content(message)
15
+ # Append the model's response to the chat history
16
+ chat_history.append((message, responce.text))
17
+ return "", chat_history
18
+
19
+ # Define the Gradio interface with a Chatbot component
20
+ with gr.Blocks() as demo:
21
+ chatbot = gr.Chatbot()
22
+ msg = gr.Textbox()
23
+ clear = gr.ClearButton([msg, chatbot])
24
+
25
+ msg.submit(get_gemini_responces, [msg, chatbot], [msg, chatbot])
26
+
27
+ # Launch the Gradio app
28
+ if __name__ == "__main__":
29
+ demo.launch()