Jd Vijay commited on
Commit
1922b90
Β·
verified Β·
1 Parent(s): c71a8bf

Clean Gradio 6 compatible app

Browse files
Files changed (1) hide show
  1. app.py +36 -102
app.py CHANGED
@@ -1,130 +1,64 @@
1
  """
2
  JD OpenManus Engine - Web UI for AI Agent Interactions
3
- A sleek, modern dark-themed Gradio interface
4
  """
5
-
6
  import gradio as gr
7
  import os
8
 
9
- # ============== UI Configuration ==============
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
- # ============== Chat Function ==============
21
- def chat_response(prompt: str, history: list) -> tuple:
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 = "⚠️ Please configure your API Key in the settings panel first."
32
  elif not agent_config.get("base_url"):
33
- response = "⚠️ Please configure your Base URL in the settings panel first."
34
  else:
35
- response = f"πŸ“ Message received!\n\nConfig:\n- Base URL: {agent_config.get('base_url', 'Not set')}\n- Model: {agent_config.get('model_name', 'default')}\n\nπŸ’‘ This is a demo response. Connect your OpenManus API to enable full functionality."
36
-
37
- # Add assistant response
38
  history.append({"role": "assistant", "content": response})
39
-
40
  return history, ""
41
 
42
- def save_config(base_url: str, model_name: str, api_key: str):
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 "βœ… Configuration saved!"
48
 
49
- # ============== Build UI ==============
50
- with gr.Blocks(title="JD OpenManus Engine", theme=THEME) as demo:
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("πŸ’¬ Chat"):
 
 
63
  with gr.Row():
64
- with gr.Column(scale=3):
65
- chatbot = gr.Chatbot(height=500, bubble_full_width=False)
66
-
67
- with gr.Row():
68
- msg_input = gr.Textbox(
69
- placeholder="Type your message here...",
70
- show_label=False,
71
- lines=3,
72
- scale=4
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
- # Chat handlers
103
- submit_btn.click(chat_response, inputs=[msg_input, chatbot], outputs=[chatbot, msg_input])
104
- msg_input.submit(chat_response, inputs=[msg_input, chatbot], outputs=[chatbot, msg_input])
105
- clear_btn.click(lambda: ([], ""), outputs=[chatbot, msg_input])
106
- save_btn.click(save_config, inputs=[base_url, model_name, api_key], outputs=[config_status])
107
 
108
- with gr.Tab("πŸ“ Files"):
109
- gr.Markdown("### πŸ“€ File Upload")
110
- gr.Markdown("Upload files for the AI agent to process.")
111
- file_input = gr.File(file_count="multiple", label="Upload Files")
112
 
113
- with gr.Tab("ℹ️ About"):
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
- # ============== Launch ==============
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)