Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,11 +46,11 @@ async def run_browser_task(task, model="gpt-4o-mini"):
|
|
| 46 |
"""Run a browser automation task using browser-use"""
|
| 47 |
try:
|
| 48 |
# Initialize the LLM based on the model name
|
| 49 |
-
if model.startswith(
|
| 50 |
llm = ChatOpenAI(model=model, temperature=0.1)
|
| 51 |
-
elif model.startswith(
|
| 52 |
llm = ChatAnthropic(model=model, temperature=0.1)
|
| 53 |
-
elif model.startswith(
|
| 54 |
llm = ChatGoogleGenerativeAI(model=model, temperature=0.1)
|
| 55 |
else:
|
| 56 |
raise ValueError(f"Unsupported model: {model}")
|
|
@@ -73,12 +73,12 @@ async def run_browser_task(task, model="gpt-4o-mini"):
|
|
| 73 |
"task": task
|
| 74 |
}
|
| 75 |
|
| 76 |
-
@app.route(
|
| 77 |
def home():
|
| 78 |
"""Serve the HTML interface"""
|
| 79 |
-
return send_from_directory(
|
| 80 |
|
| 81 |
-
@app.route(
|
| 82 |
def api_docs():
|
| 83 |
"""API documentation endpoint"""
|
| 84 |
return jsonify({
|
|
@@ -99,14 +99,14 @@ def api_docs():
|
|
| 99 |
"model": "gpt-4o-mini (optional, default)"
|
| 100 |
},
|
| 101 |
"example": {
|
| 102 |
-
"task": "Go to google.com and search for
|
| 103 |
"model": "gpt-4o-mini"
|
| 104 |
}
|
| 105 |
}
|
| 106 |
}
|
| 107 |
})
|
| 108 |
|
| 109 |
-
@app.route(
|
| 110 |
def health():
|
| 111 |
"""Health check endpoint"""
|
| 112 |
return jsonify({
|
|
@@ -115,7 +115,7 @@ def health():
|
|
| 115 |
"version": "1.0.0"
|
| 116 |
})
|
| 117 |
|
| 118 |
-
@app.route(
|
| 119 |
def status():
|
| 120 |
"""Get server status and configuration"""
|
| 121 |
return jsonify({
|
|
@@ -137,21 +137,21 @@ def status():
|
|
| 137 |
]
|
| 138 |
})
|
| 139 |
|
| 140 |
-
@app.route(
|
| 141 |
def run_task():
|
| 142 |
"""Run a browser automation task"""
|
| 143 |
try:
|
| 144 |
# Get request data
|
| 145 |
data = request.get_json()
|
| 146 |
|
| 147 |
-
if not data or
|
| 148 |
return jsonify({
|
| 149 |
"success": False,
|
| 150 |
-
"error": "Missing
|
| 151 |
}), 400
|
| 152 |
|
| 153 |
-
task = data[
|
| 154 |
-
model = data.get(
|
| 155 |
|
| 156 |
# Validate API keys
|
| 157 |
if not os.getenv("OPENAI_API_KEY") and not os.getenv("ANTHROPIC_API_KEY") and not os.getenv("GOOGLE_API_KEY"):
|
|
@@ -185,7 +185,7 @@ def run_task():
|
|
| 185 |
"error": f"Server error: {str(e)}"
|
| 186 |
}), 500
|
| 187 |
|
| 188 |
-
if __name__ ==
|
| 189 |
print("Starting Browser-Use Server...")
|
| 190 |
print("Make sure you have set your API keys:")
|
| 191 |
print("- OPENAI_API_KEY for OpenAI models")
|
|
@@ -193,5 +193,5 @@ if __name__ == \'__main__\':
|
|
| 193 |
print("- GOOGLE_API_KEY for Google Gemini models")
|
| 194 |
|
| 195 |
# Run the Flask app
|
| 196 |
-
app.run(host
|
| 197 |
|
|
|
|
| 46 |
"""Run a browser automation task using browser-use"""
|
| 47 |
try:
|
| 48 |
# Initialize the LLM based on the model name
|
| 49 |
+
if model.startswith("gpt"):
|
| 50 |
llm = ChatOpenAI(model=model, temperature=0.1)
|
| 51 |
+
elif model.startswith("claude"):
|
| 52 |
llm = ChatAnthropic(model=model, temperature=0.1)
|
| 53 |
+
elif model.startswith("gemini"):
|
| 54 |
llm = ChatGoogleGenerativeAI(model=model, temperature=0.1)
|
| 55 |
else:
|
| 56 |
raise ValueError(f"Unsupported model: {model}")
|
|
|
|
| 73 |
"task": task
|
| 74 |
}
|
| 75 |
|
| 76 |
+
@app.route("/")
|
| 77 |
def home():
|
| 78 |
"""Serve the HTML interface"""
|
| 79 |
+
return send_from_directory("static", "index.html")
|
| 80 |
|
| 81 |
+
@app.route("/api")
|
| 82 |
def api_docs():
|
| 83 |
"""API documentation endpoint"""
|
| 84 |
return jsonify({
|
|
|
|
| 99 |
"model": "gpt-4o-mini (optional, default)"
|
| 100 |
},
|
| 101 |
"example": {
|
| 102 |
+
"task": "Go to google.com and search for 'Python programming'",
|
| 103 |
"model": "gpt-4o-mini"
|
| 104 |
}
|
| 105 |
}
|
| 106 |
}
|
| 107 |
})
|
| 108 |
|
| 109 |
+
@app.route("/health")
|
| 110 |
def health():
|
| 111 |
"""Health check endpoint"""
|
| 112 |
return jsonify({
|
|
|
|
| 115 |
"version": "1.0.0"
|
| 116 |
})
|
| 117 |
|
| 118 |
+
@app.route("/status")
|
| 119 |
def status():
|
| 120 |
"""Get server status and configuration"""
|
| 121 |
return jsonify({
|
|
|
|
| 137 |
]
|
| 138 |
})
|
| 139 |
|
| 140 |
+
@app.route("/run-task", methods=["POST"])
|
| 141 |
def run_task():
|
| 142 |
"""Run a browser automation task"""
|
| 143 |
try:
|
| 144 |
# Get request data
|
| 145 |
data = request.get_json()
|
| 146 |
|
| 147 |
+
if not data or "task" not in data:
|
| 148 |
return jsonify({
|
| 149 |
"success": False,
|
| 150 |
+
"error": "Missing 'task' in request body"
|
| 151 |
}), 400
|
| 152 |
|
| 153 |
+
task = data["task"]
|
| 154 |
+
model = data.get("model", "gpt-4o-mini")
|
| 155 |
|
| 156 |
# Validate API keys
|
| 157 |
if not os.getenv("OPENAI_API_KEY") and not os.getenv("ANTHROPIC_API_KEY") and not os.getenv("GOOGLE_API_KEY"):
|
|
|
|
| 185 |
"error": f"Server error: {str(e)}"
|
| 186 |
}), 500
|
| 187 |
|
| 188 |
+
if __name__ == "__main__":
|
| 189 |
print("Starting Browser-Use Server...")
|
| 190 |
print("Make sure you have set your API keys:")
|
| 191 |
print("- OPENAI_API_KEY for OpenAI models")
|
|
|
|
| 193 |
print("- GOOGLE_API_KEY for Google Gemini models")
|
| 194 |
|
| 195 |
# Run the Flask app
|
| 196 |
+
app.run(host="0.0.0.0", port=7860, debug=False)
|
| 197 |
|