File size: 2,262 Bytes
6839ece
c71a8bf
1922b90
6839ece
 
7983734
 
1922b90
c71a8bf
7983734
1922b90
 
7983734
 
c71a8bf
 
1922b90
c71a8bf
1922b90
c71a8bf
1922b90
7983734
 
6839ece
1922b90
c71a8bf
1922b90
c71a8bf
1922b90
c71a8bf
1922b90
 
 
c71a8bf
1922b90
 
 
c71a8bf
1922b90
 
 
 
 
 
 
 
 
c71a8bf
1922b90
 
 
 
c71a8bf
1922b90
 
 
c71a8bf
1922b90
 
6839ece
1922b90
6839ece
c71a8bf
1922b90
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
"""
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)