Kate Forsberg
new
df7050b
raw
history blame
1.43 kB
import gradio as gr
from uuid import uuid4 as uuid
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()
gr.State(value=f'{str(uuid())}.json')
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=gr.State().value
)),
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."
) ]
)
gr.State()
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"))