-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.py
113 lines (96 loc) · 3.69 KB
/
app.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import gradio as gr
import tomli
import logging
import asyncio
from pathlib import Path
from run import execute_task
from run import TaskRequest
def load_config():
"""Load configuration file"""
with open("./inference/configs/setting.toml", "rb") as f:
return tomli.load(f)
def setup_logging(config):
"""Initialize logging configuration"""
log_dir = Path(config['basic']['log_dir'])
log_dir.mkdir(parents=True, exist_ok=True)
logging.basicConfig(
level=getattr(logging, config['basic']['log_level']),
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(log_dir / 'inference.log'),
logging.StreamHandler()
]
)
async def run_inference(instruction: str, mode: str, model: str):
"""Run inference pipeline"""
try:
config = load_config()
setup_logging(config)
task_request = TaskRequest(
task_name=instruction,
observation_mode=mode,
planning_text_model=model,
global_reward_text_model=model,
toml_path="./inference/configs/setting.toml"
)
result = await execute_task(task_request)
return f"Execution completed successfully!\nResult: {result}"
except Exception as e:
error_msg = f"Error during inference: {str(e)}"
logging.error(error_msg)
return error_msg
def inference_interface(instruction: str, mode: str, model: str):
return asyncio.run(run_inference(instruction, mode, model))
def use_example_1():
return "Find all latest blog posts on iMean.ai"
def use_example_2():
return "Find me paper submission dates of ACL2025"
def create_demo():
config = load_config()
with gr.Blocks(title="Open-Operator") as demo:
gr.Markdown("""
# Open-Operator
Enter an instruction and select mode and model to execute the web agent.
""")
with gr.Row():
with gr.Column(scale=1):
instruction_input = gr.Textbox(
label="Enter your instruction",
placeholder="Type your instruction here or use example tasks below..."
)
with gr.Column(scale=1):
example1_btn = gr.Button(
"Find all latest blog posts on iMean.ai",
size="sm",
min_width=100
)
example2_btn = gr.Button(
"Find paper submission dates of ACL2025",
size="sm",
min_width=100
)
mode_input = gr.Dropdown(
choices=["dom"],
value="dom",
label="Select Mode"
)
model_input = gr.Dropdown(
choices=config['model']['available_models'],
label="Select Model",
value=config['model']['selected']
)
submit_btn = gr.Button("Execute", variant="primary")
output = gr.Textbox(label="Result")
# Button click handlers
example1_btn.click(fn=use_example_1, outputs=[instruction_input])
example2_btn.click(fn=use_example_2, outputs=[instruction_input])
submit_btn.click(
fn=inference_interface,
inputs=[instruction_input, mode_input, model_input],
outputs=output
)
return demo
if __name__ == "__main__":
demo = create_demo()
# Launch with share=True to get a public URL
demo.launch(share=True, server_name="0.0.0.0")