Spaces:
Sleeping
Sleeping
File size: 1,888 Bytes
2329051 df7050b e96f6f0 2329051 f787fa1 2329051 e96f6f0 2329051 49630fa 2329051 f787fa1 df7050b 2329051 df7050b 2329051 df7050b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import gradio as gr
from uuid import uuid4 as uuid
from huggingface_hub import HfApi
from typing import Any
from griptape.structures import Agent, Workflow
from griptape.tasks import PromptTask
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."
) ]
)
workflow = Workflow()
start_task = PromptTask("I will provide you two dog breeds to compare", id="START")
end_task = PromptTask("How are the dog breeds different", id="END")
workflow.add_task(start_task)
workflow.add_task(end_task)
dog_task = PromptTask("Poodle and a Labrador", id="DOG")
workflow.insert_tasks(start_task,[dog_task],end_task)
def use_workflow(message:str, history) -> Any:
response = workflow.run()
return response.output.value
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"))
|