|
|
|
@ -6,13 +6,20 @@ import glob
|
|
|
|
|
import base64
|
|
|
|
|
from langchain.llms import OpenAIChat
|
|
|
|
|
from swarms.agents import OmniModalAgent
|
|
|
|
|
import gradio_client as grc
|
|
|
|
|
|
|
|
|
|
grc.Client("Wawaa/omniagent").deploy_discord()
|
|
|
|
|
|
|
|
|
|
# Function to convert image to base64
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def image_to_base64(image_path):
|
|
|
|
|
with open(image_path, "rb") as image_file:
|
|
|
|
|
return base64.b64encode(image_file.read()).decode()
|
|
|
|
|
|
|
|
|
|
# Function to get the most recently created image in the directory
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_latest_image():
|
|
|
|
|
list_of_files = glob.glob('./*.png') # Replace with your image file type
|
|
|
|
|
if not list_of_files:
|
|
|
|
@ -20,6 +27,7 @@ def get_latest_image():
|
|
|
|
|
latest_file = max(list_of_files, key=os.path.getctime)
|
|
|
|
|
return latest_file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Initialize your OmniModalAgent
|
|
|
|
|
llm = OpenAIChat(model_name="gpt-4") # Replace with your actual initialization
|
|
|
|
|
agent = OmniModalAgent(llm) # Replace with your actual initialization
|
|
|
|
@ -28,6 +36,8 @@ agent = OmniModalAgent(llm) # Replace with your actual initialization
|
|
|
|
|
chat_history = []
|
|
|
|
|
|
|
|
|
|
# Function to update chat
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_chat(user_input):
|
|
|
|
|
global chat_history
|
|
|
|
|
chat_history.append({"type": "user", "content": user_input})
|
|
|
|
@ -50,6 +60,7 @@ def update_chat(user_input):
|
|
|
|
|
|
|
|
|
|
# Function to render chat as HTML
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def render_chat(chat_history):
|
|
|
|
|
chat_str = "<div style='max-height:400px;overflow-y:scroll;'>"
|
|
|
|
|
for message in chat_history:
|
|
|
|
@ -64,6 +75,7 @@ def render_chat(chat_history):
|
|
|
|
|
chat_str += "</div>"
|
|
|
|
|
return chat_str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Define Gradio interface
|
|
|
|
|
iface = Interface(
|
|
|
|
|
fn=update_chat,
|
|
|
|
@ -73,11 +85,14 @@ iface = Interface(
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Function to update the chat display
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_display():
|
|
|
|
|
global chat_history
|
|
|
|
|
while True:
|
|
|
|
|
iface.update(render_chat(chat_history))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Run the update_display function in a separate thread
|
|
|
|
|
threading.Thread(target=update_display).start()
|
|
|
|
|
|
|
|
|
|