Kate Forsberg commited on
Commit
2329051
·
1 Parent(s): c8543a0

add application file

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from typing import Any
3
+ from griptape.structures import Agent
4
+ from griptape.drivers import LocalConversationMemoryDriver
5
+ from griptape.memory.structure import ConversationMemory
6
+ from griptape.tools import Calculator
7
+ from griptape.rules import Rule
8
+ import time
9
+
10
+
11
+ def user(user_message, history):
12
+ history.append([user_message, None])
13
+ return ("", history)
14
+
15
+ def bot(history):
16
+ response = agent.send_message(history[-1][0])
17
+ history[-1][1] = ""
18
+ for character in response:
19
+ history[-1][1] += character
20
+
21
+ time.sleep(0.005)
22
+
23
+ yield history
24
+
25
+ agent = Agent(
26
+ conversation_memory=ConversationMemory(
27
+ driver=LocalConversationMemoryDriver(
28
+ file_path="conversation_memory.json"
29
+ )),
30
+ tools=[Calculator()],
31
+ rules=[
32
+ Rule(
33
+ value = "You are an intelligent agent tasked with answering questions."
34
+ ),
35
+ Rule(
36
+ value = "All of your responses are less than 5 sentences."
37
+ ) ]
38
+ )
39
+
40
+ def send_message(message:str, history,) -> Any:
41
+ response = agent.run(message)
42
+ return response.output.value
43
+
44
+ demo = gr.ChatInterface(
45
+ fn=send_message
46
+ )
47
+ demo.launch(
48
+ auth=("griptape","griptaper"),
49
+ share=True)