Spaces:
Sleeping
Sleeping
import nltk | |
from spacy.lang.en import English | |
# Example input: process description | |
process_description = """ | |
The accounts payable team receives invoices via email. | |
They verify the invoice details, check for duplicates, and approve payment. | |
""" | |
# Preprocess the text | |
def preprocess_text(text): | |
tokenizer = English() | |
tokens = tokenizer(text) | |
processed_text = [token.lemma_ for token in tokens if not token.is_stop] | |
return ' '.join(processed_text) | |
processed_desc = preprocess_text(process_description) | |
print(processed_desc) | |
import spacy | |
nlp = spacy.load('en_core_web_sm') | |
def extract_entities(text): | |
doc = nlp(text) | |
entities = [(ent.text, ent.label_) for ent in doc.ents] | |
return entities | |
entities = extract_entities(process_description) | |
print("Extracted Entities:", entities) | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
from sklearn.svm import SVC | |
# Sample training data (simplified) | |
X = [ | |
"receive invoices via email", # Automatable | |
"verify invoice details", # Automatable | |
"approve payment manually" # Non-automatable | |
] | |
y = [1, 1, 0] | |
# Feature extraction | |
vectorizer = TfidfVectorizer() | |
X_vec = vectorizer.fit_transform(X) | |
# Train a simple SVM | |
model = SVC() | |
model.fit(X_vec, y) | |
# Predict automation feasibility | |
def predict_automation_feasibility(text): | |
text_vec = vectorizer.transform([text]) | |
return model.predict(text_vec)[0] | |
print(predict_automation_feasibility("check for duplicates")) # Output: 1 (Automatable) | |
# Example workflow for UiPath | |
def generate_uipath_workflow(tasks): | |
workflow = f""" | |
<Workflow [ContentUIVersion='1.0.0.0' TargetPlatform='.NETFramework,Version=v6.0' TargetRuntime='V6_0' HostRuntimeERO='255,255'> | |
<Variable Type='Object' Name='invoiceDetails' /> | |
{''.join([f"<Variable Type='Object' Name='task_{task}' />" for task in tasks])} | |
<Sequence> | |
{''.join([f"<Activitysqueeze Code='GeneratedActivity严格落实任务_{task}' />" for task in tasks])} | |
</Sequence> | |
</Workflow> | |
""" | |
return workflow | |
tasks = ["receive_invoices", "verify_details", "approve_payment"] | |
workflow = generate_uipath_workflow(tasks) | |
print(workflow) | |
# Example workflow for UiPath | |
def generate_uipath_workflow(tasks): | |
workflow = f""" | |
<Workflow [ContentUIVersion='1.0.0.0' TargetPlatform='.NETFramework,Version=v6.0' TargetRuntime='V6_0' HostRuntimeERO='255,255'> | |
<Variable Type='Object' Name='invoiceDetails' /> | |
{''.join([f"<Variable Type='Object' Name='task_{task}' />" for task in tasks])} | |
<Sequence> | |
{''.join([f"<Activitysqueeze Code='GeneratedActivity严格落实任务_{task}' />" for task in tasks])} | |
</Sequence> | |
</Workflow> | |
""" | |
return workflow | |
tasks = ["receive_invoices", "verify_details", "approve_payment"] | |
workflow = generate_uipath_workflow(tasks) | |
print(workflow) | |
# Example: Connect to UiPath Orchestrator API | |
import requests | |
def execute_workflow(workflow, uipath_uri, api_key): | |
headers = { | |
"Authorization": f"Bearer {api_key}", | |
"Content-Type": "application/xml" | |
} | |
response = requests.post(f"{uipath_uri}/api/workflows", headers=headers, data=workflow) | |
return response.json() | |
# Example API call | |
uipath_uri = "https://your-uipath-orchestrator-url" | |
api_key = "your-api-key" | |
response = execute_workflow(workflow, uipath_uri, api_key) | |
print("Workflow Execution Response:", response) | |