kendrickfff commited on
Commit
b0397d2
·
verified ·
1 Parent(s): 047c0ab

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install langchain google-generativeai langchain-google-genai gradio
2
+ import os
3
+
4
+ # Set the path to the service account key
5
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/content/firm-catalyst-437006-s4-407500537db5.json"
6
+
7
+ import os
8
+ import gradio as gr
9
+ from langchain_google_genai.chat_models import ChatGoogleGenerativeAI
10
+
11
+ # Set the path to the service account key
12
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/content/firm-catalyst-437006-s4-407500537db5.json"
13
+
14
+ # Initialize the LLM
15
+ llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro")
16
+
17
+ def chat_with_gemini(user_input):
18
+ try:
19
+ # Prepare the prompt in the expected format
20
+ response = llm.predict(user_input) # Using the 'predict' method instead
21
+ return response
22
+ except Exception as e:
23
+ return f"Error: {str(e)}"
24
+
25
+ # Create a Gradio interface
26
+ iface = gr.Interface(
27
+ fn=chat_with_gemini,
28
+ inputs="text",
29
+ outputs="text",
30
+ title="Chatbot with Gemini 1.5",
31
+ description="Ask me anything!"
32
+ )
33
+
34
+ # Launch the interface with debugging
35
+ iface.launch(debug=True)