Spaces:
Sleeping
Sleeping
| """ | |
| JD OpenManus Engine - Web UI for AI Agent Interactions | |
| Compatible with Gradio 6.x | |
| """ | |
| import gradio as gr | |
| import os | |
| # Global State | |
| agent_config = {"base_url": "", "model_name": "", "api_key": ""} | |
| # Chat Function | |
| def chat_response(prompt, history): | |
| if not prompt.strip(): | |
| return history, "" | |
| history.append({"role": "user", "content": prompt}) | |
| if not agent_config.get("api_key"): | |
| response = "Please configure API Key first." | |
| elif not agent_config.get("base_url"): | |
| response = "Please configure Base URL first." | |
| else: | |
| response = f"Message received! Config: {agent_config.get('base_url')}" | |
| history.append({"role": "assistant", "content": response}) | |
| return history, "" | |
| def save_config(base_url, model_name, api_key): | |
| agent_config["base_url"] = base_url | |
| agent_config["model_name"] = model_name | |
| agent_config["api_key"] = api_key | |
| return "Configuration saved!" | |
| # Build UI | |
| with gr.Blocks(title="JD OpenManus Engine") as demo: | |
| gr.Markdown("# JD OpenManus Engine") | |
| with gr.Tab("Chat"): | |
| chatbot = gr.Chatbot(height=500) | |
| msg_input = gr.Textbox(placeholder="Type message...", lines=3) | |
| with gr.Row(): | |
| submit_btn = gr.Button("Send", variant="primary") | |
| clear_btn = gr.Button("Clear") | |
| gr.Markdown("### Configuration") | |
| base_url = gr.Textbox(label="Base URL") | |
| model_name = gr.Textbox(label="Model Name") | |
| api_key = gr.Textbox(label="API Key", type="password") | |
| save_btn = gr.Button("Save") | |
| config_status = gr.Markdown("") | |
| submit_btn.click(chat_response, [msg_input, chatbot], [chatbot, msg_input]) | |
| msg_input.submit(chat_response, [msg_input, chatbot], [chatbot, msg_input]) | |
| clear_btn.click(lambda: ([], ""), [chatbot, msg_input]) | |
| save_btn.click(save_config, [base_url, model_name, api_key], [config_status]) | |
| with gr.Tab("Files"): | |
| gr.Markdown("### File Upload") | |
| file_input = gr.File(file_count="multiple") | |
| with gr.Tab("About"): | |
| gr.Markdown("## JD OpenManus Engine\nVersion 1.0.0") | |
| # Launch | |
| if __name__ == "__main__": | |
| port = int(os.environ.get("PORT", "7860")) | |
| demo.launch(server_name="0.0.0.0", server_port=port) | |