Spaces:
Sleeping
Sleeping
Commit
·
e84b6e6
1
Parent(s):
4d23ea1
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
3 |
+
from langchain.memory import ConversationBufferMemory
|
4 |
+
from langchain.chains import ConversationChain
|
5 |
+
import os
|
6 |
+
|
7 |
+
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
8 |
+
|
9 |
+
llm = ChatGoogleGenerativeAI(
|
10 |
+
google_api_key=GOOGLE_API_KEY,
|
11 |
+
model="gemini-pro",
|
12 |
+
temperature=0.7
|
13 |
+
)
|
14 |
+
conversation = ConversationChain(
|
15 |
+
llm=llm,
|
16 |
+
verbose=True,
|
17 |
+
memory=ConversationBufferMemory()
|
18 |
+
)
|
19 |
+
def chat(prompt):
|
20 |
+
res = conversation.predict(input=prompt)
|
21 |
+
return res, conversation.memory.chat_memory.messages
|
22 |
+
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=chat,
|
25 |
+
inputs=[gr.Textbox(lines=2, placeholder="Type your message here")],
|
26 |
+
outputs=[gr.Textbox(label="Response"), gr.Textbox(label="Conversation History", lines=10)], # Adjusted for multiple lines
|
27 |
+
title="Chat with Gemini-Pro",
|
28 |
+
#live=True, # Enable live updates
|
29 |
+
)
|
30 |
+
|
31 |
+
iface.launch(debug=True)
|