Spaces:
Paused
Paused
Jd Vijay commited on
Clean Gradio 6 compatible app
Browse files
app.py
CHANGED
|
@@ -1,130 +1,64 @@
|
|
| 1 |
"""
|
| 2 |
JD OpenManus Engine - Web UI for AI Agent Interactions
|
| 3 |
-
|
| 4 |
"""
|
| 5 |
-
|
| 6 |
import gradio as gr
|
| 7 |
import os
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
THEME = gr.themes.Soft(
|
| 11 |
-
primary_hue="indigo",
|
| 12 |
-
secondary_hue="purple",
|
| 13 |
-
neutral_hue="slate",
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
# ============== Global State ==============
|
| 17 |
agent_config = {"base_url": "", "model_name": "", "api_key": ""}
|
| 18 |
-
chat_history = []
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
def chat_response(prompt
|
| 22 |
-
"""Process chat messages"""
|
| 23 |
if not prompt.strip():
|
| 24 |
return history, ""
|
| 25 |
-
|
| 26 |
-
# Add user message
|
| 27 |
history.append({"role": "user", "content": prompt})
|
| 28 |
-
|
| 29 |
-
# Generate response based on config
|
| 30 |
if not agent_config.get("api_key"):
|
| 31 |
-
response = "
|
| 32 |
elif not agent_config.get("base_url"):
|
| 33 |
-
response = "
|
| 34 |
else:
|
| 35 |
-
response = f"
|
| 36 |
-
|
| 37 |
-
# Add assistant response
|
| 38 |
history.append({"role": "assistant", "content": response})
|
| 39 |
-
|
| 40 |
return history, ""
|
| 41 |
|
| 42 |
-
def save_config(base_url
|
| 43 |
-
"""Save API configuration"""
|
| 44 |
agent_config["base_url"] = base_url
|
| 45 |
-
agent_config["model_name"] = model_name
|
| 46 |
agent_config["api_key"] = api_key
|
| 47 |
-
return "
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
with gr.Blocks(title="JD OpenManus Engine"
|
| 51 |
-
gr.Markdown(""
|
| 52 |
-
<div style="text-align: center; padding: 20px 0; border-bottom: 1px solid #333; margin-bottom: 20px;">
|
| 53 |
-
<h1 style="font-size: 28px; font-weight: 700; background: linear-gradient(135deg, #6366f1, #a855f7); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">
|
| 54 |
-
π€ JD OpenManus Engine
|
| 55 |
-
</h1>
|
| 56 |
-
<p style="color: #a0a0a0; margin-top: 8px;">
|
| 57 |
-
AI Agent Interface β’ Powered by OpenManus Framework
|
| 58 |
-
</p>
|
| 59 |
-
</div>
|
| 60 |
-
""")
|
| 61 |
|
| 62 |
-
with gr.Tab("
|
|
|
|
|
|
|
| 63 |
with gr.Row():
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
with gr.Row():
|
| 76 |
-
submit_btn = gr.Button("Send", variant="primary")
|
| 77 |
-
clear_btn = gr.Button("Clear Chat", variant="secondary")
|
| 78 |
-
|
| 79 |
-
with gr.Column(scale=1):
|
| 80 |
-
with gr.Group():
|
| 81 |
-
gr.Markdown("### βοΈ Configuration")
|
| 82 |
-
|
| 83 |
-
base_url = gr.Textbox(
|
| 84 |
-
label="Base URL",
|
| 85 |
-
placeholder="https://api.openai.com/v1"
|
| 86 |
-
)
|
| 87 |
-
|
| 88 |
-
model_name = gr.Textbox(
|
| 89 |
-
label="Model Name",
|
| 90 |
-
placeholder="gpt-4-turbo"
|
| 91 |
-
)
|
| 92 |
-
|
| 93 |
-
api_key = gr.Textbox(
|
| 94 |
-
label="API Key",
|
| 95 |
-
placeholder="sk-...",
|
| 96 |
-
type="password"
|
| 97 |
-
)
|
| 98 |
-
|
| 99 |
-
save_btn = gr.Button("πΎ Save", variant="primary")
|
| 100 |
-
config_status = gr.Markdown("")
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
save_btn.click(save_config, inputs=[base_url, model_name, api_key], outputs=[config_status])
|
| 107 |
|
| 108 |
-
with gr.Tab("
|
| 109 |
-
gr.Markdown("###
|
| 110 |
-
gr.
|
| 111 |
-
file_input = gr.File(file_count="multiple", label="Upload Files")
|
| 112 |
|
| 113 |
-
with gr.Tab("
|
| 114 |
-
gr.Markdown(""
|
| 115 |
-
## π€ JD OpenManus Engine
|
| 116 |
-
|
| 117 |
-
**Version:** 1.0.0
|
| 118 |
-
**Framework:** OpenManus
|
| 119 |
-
|
| 120 |
-
### Features:
|
| 121 |
-
- π¬ Chat Interface
|
| 122 |
-
- βοΈ Flexible Configuration
|
| 123 |
-
- π File Upload Support
|
| 124 |
-
- π Dark Theme UI
|
| 125 |
-
""")
|
| 126 |
|
| 127 |
-
#
|
| 128 |
if __name__ == "__main__":
|
| 129 |
port = int(os.environ.get("PORT", "7860"))
|
| 130 |
-
demo.launch(server_name="0.0.0.0", server_port=port)
|
|
|
|
| 1 |
"""
|
| 2 |
JD OpenManus Engine - Web UI for AI Agent Interactions
|
| 3 |
+
Compatible with Gradio 6.x
|
| 4 |
"""
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
import os
|
| 7 |
|
| 8 |
+
# Global State
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
agent_config = {"base_url": "", "model_name": "", "api_key": ""}
|
|
|
|
| 10 |
|
| 11 |
+
# Chat Function
|
| 12 |
+
def chat_response(prompt, history):
|
|
|
|
| 13 |
if not prompt.strip():
|
| 14 |
return history, ""
|
|
|
|
|
|
|
| 15 |
history.append({"role": "user", "content": prompt})
|
|
|
|
|
|
|
| 16 |
if not agent_config.get("api_key"):
|
| 17 |
+
response = "Please configure API Key first."
|
| 18 |
elif not agent_config.get("base_url"):
|
| 19 |
+
response = "Please configure Base URL first."
|
| 20 |
else:
|
| 21 |
+
response = f"Message received! Config: {agent_config.get('base_url')}"
|
|
|
|
|
|
|
| 22 |
history.append({"role": "assistant", "content": response})
|
|
|
|
| 23 |
return history, ""
|
| 24 |
|
| 25 |
+
def save_config(base_url, model_name, api_key):
|
|
|
|
| 26 |
agent_config["base_url"] = base_url
|
| 27 |
+
agent_config["model_name"] = model_name
|
| 28 |
agent_config["api_key"] = api_key
|
| 29 |
+
return "Configuration saved!"
|
| 30 |
|
| 31 |
+
# Build UI
|
| 32 |
+
with gr.Blocks(title="JD OpenManus Engine") as demo:
|
| 33 |
+
gr.Markdown("# JD OpenManus Engine")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
with gr.Tab("Chat"):
|
| 36 |
+
chatbot = gr.Chatbot(height=500)
|
| 37 |
+
msg_input = gr.Textbox(placeholder="Type message...", lines=3)
|
| 38 |
with gr.Row():
|
| 39 |
+
submit_btn = gr.Button("Send", variant="primary")
|
| 40 |
+
clear_btn = gr.Button("Clear")
|
| 41 |
+
|
| 42 |
+
gr.Markdown("### Configuration")
|
| 43 |
+
base_url = gr.Textbox(label="Base URL")
|
| 44 |
+
model_name = gr.Textbox(label="Model Name")
|
| 45 |
+
api_key = gr.Textbox(label="API Key", type="password")
|
| 46 |
+
save_btn = gr.Button("Save")
|
| 47 |
+
config_status = gr.Markdown("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
submit_btn.click(chat_response, [msg_input, chatbot], [chatbot, msg_input])
|
| 50 |
+
msg_input.submit(chat_response, [msg_input, chatbot], [chatbot, msg_input])
|
| 51 |
+
clear_btn.click(lambda: ([], ""), [chatbot, msg_input])
|
| 52 |
+
save_btn.click(save_config, [base_url, model_name, api_key], [config_status])
|
|
|
|
| 53 |
|
| 54 |
+
with gr.Tab("Files"):
|
| 55 |
+
gr.Markdown("### File Upload")
|
| 56 |
+
file_input = gr.File(file_count="multiple")
|
|
|
|
| 57 |
|
| 58 |
+
with gr.Tab("About"):
|
| 59 |
+
gr.Markdown("## JD OpenManus Engine\nVersion 1.0.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
# Launch
|
| 62 |
if __name__ == "__main__":
|
| 63 |
port = int(os.environ.get("PORT", "7860"))
|
| 64 |
+
demo.launch(server_name="0.0.0.0", server_port=port)
|