Kate Forsberg
ahh
e96f6f0
raw
history blame
1.35 kB
import gradio as gr
from huggingface_hub import HfApi
from typing import Any
from griptape.structures import Agent
from griptape.drivers import LocalConversationMemoryDriver
from griptape.memory.structure import ConversationMemory
from griptape.tools import Calculator
from griptape.rules import Rule
import time
repo_id = "kateforsberg/gradio-test"
api = HfApi()
def user(user_message, history):
history.append([user_message, None])
return ("", history)
def bot(history):
response = agent.send_message(history[-1][0])
history[-1][1] = ""
for character in response:
history[-1][1] += character
time.sleep(0.005)
yield history
agent = Agent(
conversation_memory=ConversationMemory(
driver=LocalConversationMemoryDriver(
file_path="conversation_memory.json"
)),
tools=[Calculator()],
rules=[
Rule(
value = "You are an intelligent agent tasked with answering questions."
),
Rule(
value = "All of your responses are less than 5 sentences."
) ]
)
def send_message(message:str, history,) -> Any:
response = agent.run(message)
return response.output.value
demo = gr.ChatInterface(
fn=send_message
)
demo.launch(
auth=("griptape","griptaper"))