Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,124 +1,92 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# Preprocess the text
|
| 11 |
-
def preprocess_text(text):
|
| 12 |
-
tokenizer = English()
|
| 13 |
-
tokens = tokenizer(text)
|
| 14 |
-
processed_text = [token.lemma_ for token in tokens if not token.is_stop]
|
| 15 |
-
return ' '.join(processed_text)
|
| 16 |
-
|
| 17 |
-
processed_desc = preprocess_text(process_description)
|
| 18 |
-
print(processed_desc)
|
| 19 |
-
|
| 20 |
-
|
| 21 |
import spacy
|
| 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 |
-
response = requests.post(f"{uipath_uri}/api/workflows", headers=headers, data=workflow)
|
| 107 |
-
return response.json()
|
| 108 |
-
|
| 109 |
-
# Example API call
|
| 110 |
-
uipath_uri = "https://your-uipath-orchestrator-url"
|
| 111 |
-
api_key = "your-api-key"
|
| 112 |
-
|
| 113 |
-
response = execute_workflow(workflow, uipath_uri, api_key)
|
| 114 |
-
print("Workflow Execution Response:", response)
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 1 |
+
# RPA Business Analyst AI Agent Implementation
|
| 2 |
+
# pip install pm4py neo4j rasa opencv-python pytesseract tensorflow scikit-learn
|
| 3 |
+
|
| 4 |
+
# imports
|
| 5 |
+
import pm4py
|
| 6 |
+
import cv2
|
| 7 |
+
from mss import mss
|
| 8 |
+
import pytesseract
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
import spacy
|
| 10 |
+
from neo4j import GraphDatabase
|
| 11 |
+
import numpy as np
|
| 12 |
+
import pandas as pd
|
| 13 |
+
import json
|
| 14 |
+
import tensorflow as tf
|
| 15 |
+
from sklearn.ensemble import GradientBoostingRegressor
|
| 16 |
+
|
| 17 |
+
# Process Mining Module
|
| 18 |
+
def discover_process(event_log_path, algorithm="inductive"):
|
| 19 |
+
log = pm4py.read_xes(event_log_path)
|
| 20 |
+
if algorithm == "inductive":
|
| 21 |
+
model = pm4py.discover_petri_net_inductive(log)
|
| 22 |
+
else:
|
| 23 |
+
model = pm4py.discover_petri_net_alpha(log)
|
| 24 |
+
pm4py.view_petri_net(*model)
|
| 25 |
+
return model
|
| 26 |
+
|
| 27 |
+
# Computer Vision Module
|
| 28 |
+
class ScreenCapture:
|
| 29 |
+
def capture_screen(self):
|
| 30 |
+
with mss() as sct:
|
| 31 |
+
monitor = {"top": 0, "left": 0, "width": 1920, "height": 1080}
|
| 32 |
+
img = sct.grab(monitor)
|
| 33 |
+
return cv2.cvtColor(np.array(img), cv2.COLOR_BGRA2BGR)
|
| 34 |
+
|
| 35 |
+
def extract_text(self, image):
|
| 36 |
+
return pytesseract.image_to_string(image)
|
| 37 |
+
|
| 38 |
+
# NLP Module
|
| 39 |
+
nlp_model = spacy.load("en_core_web_sm")
|
| 40 |
+
def parse_workflows(text):
|
| 41 |
+
doc = nlp_model(text)
|
| 42 |
+
return [ent.text for ent in doc.ents if ent.label_ == "WORKFLOW"]
|
| 43 |
+
|
| 44 |
+
# Requirements Analysis Module
|
| 45 |
+
driver = GraphDatabase.driver("bolt://localhost", auth=None)
|
| 46 |
+
def create_process_node(process_name, process_description):
|
| 47 |
+
with driver.session() as session:
|
| 48 |
+
session.run(
|
| 49 |
+
"MERGE (p:Process {name: $name}) SET p.description = $description",
|
| 50 |
+
name=process_name,
|
| 51 |
+
description=process_description
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# Automation Opportunity Detector
|
| 55 |
+
class SuitabilityPredictor:
|
| 56 |
+
def __init__(self, model_path):
|
| 57 |
+
self.model = tf.keras.models.load_model(model_path)
|
| 58 |
+
|
| 59 |
+
def predict(self, features):
|
| 60 |
+
return self.model.predict(features)[0][0]
|
| 61 |
+
|
| 62 |
+
def automate_suitability(process_data, model_path):
|
| 63 |
+
predictor = SuitabilityPredictor(model_path)
|
| 64 |
+
return predictor.predict(process_data)
|
| 65 |
+
|
| 66 |
+
# Main Execution Block
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
# Load Configuration
|
| 69 |
+
with open("config.json") as f:
|
| 70 |
+
config = json.load(f)
|
| 71 |
+
|
| 72 |
+
# Process Mining
|
| 73 |
+
event_log_path = "data/event_logs.xes"
|
| 74 |
+
process_model = discover_process(event_log_path, config["process_mining"]["algorithm"])
|
| 75 |
+
|
| 76 |
+
# Computer Vision
|
| 77 |
+
screen_cap = ScreenCapture()
|
| 78 |
+
screen_img = screen_cap.capture_screen()
|
| 79 |
+
screen_text = screen_cap.extract_text(screen_img)
|
| 80 |
+
|
| 81 |
+
# NLP
|
| 82 |
+
workflows = parse_workflows(screen_text)
|
| 83 |
+
|
| 84 |
+
# Knowledge Graph
|
| 85 |
+
create_process_node("Invoice Processing", "Processes vendor invoices")
|
| 86 |
+
|
| 87 |
+
# ML Suitability
|
| 88 |
+
model_path = config["ml"]["model_path"]
|
| 89 |
+
suitability_score = automate_suitability(process_data, model_path)
|
| 90 |
+
|
| 91 |
+
# Recommendation Engine
|
| 92 |
+
print(f"Automation Suitability: {suitability_score:.2f}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|