Spaces:
Build error
Build error
| import streamlit as st | |
| import spacy | |
| import requests | |
| import spacy.cli | |
| # Check if the model is installed, and download it if not | |
| try: | |
| # Try loading the model spaCy, a popular Natural Language Processing (NLP) library in Python | |
| # load the en_core_web_sm model, which is a small, pre-trained model for English provided by spaCy. | |
| # en_core_web_sm is one of the spaCy pre-trained models for English. The "sm" in its name stands for "small," | |
| # meaning this is a lightweight version of the model with a trade-off between speed and accuracy compared to larger models like en_core_web_md (medium) or en_core_web_lg (large). | |
| nlp = spacy.load("en_core_web_sm") | |
| except OSError: | |
| # If not found, download the model | |
| spacy.cli.download("en_core_web_sm") | |
| nlp = spacy.load("en_core_web_sm") | |
| # Now you can use the model | |
| doc = nlp("This is a test sentence.") | |
| print([(token.text, token.pos_) for token in doc]) | |
| # Function to trigger GitHub Actions workflow | |
| def trigger_github_action(repo_owner, repo_name, workflow_file, token): | |
| url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/actions/workflows/{workflow_file}/dispatches" | |
| headers = { | |
| "Authorization": f"Bearer {token}", | |
| "Accept": "application/vnd.github.v3+json", | |
| } | |
| data = { | |
| "ref": "main", # The branch to trigger on | |
| "inputs": { # Any additional inputs you want to pass to the workflow | |
| "deploy": "true" # example of passing an input parameter | |
| } | |
| } | |
| response = requests.post(url, json=data, headers=headers) | |
| if response.status_code == 204: | |
| return "GitHub Action triggered successfully!" | |
| else: | |
| return f"Error: {response.status_code}, {response.text}" | |
| # Streamlit app UI | |
| st.title("NLP Command Processor") | |
| st.write("Type a command to trigger GitHub Actions workflow for MuleSoft API deployment.") | |
| # User input for NLP command | |
| command = st.text_input("Enter NLP Command", "") | |
| # GitHub repo details | |
| repo_owner = "stigaditech" | |
| repo_name = "ch2-mule-api-cicd" | |
| workflow_file = "build.yml" # Name of your GitHub Actions workflow YAML file | |
| github_token = "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" # Personal Access Token with the necessary scopes | |
| # Process the command and trigger GitHub Actions | |
| if command: | |
| doc = nlp(command.lower()) # Process the command using spaCy | |
| if any(token.text in ["deploy", "hugging", "face"] for token in doc): | |
| result = trigger_github_action(repo_owner, repo_name, workflow_file, github_token) | |
| st.success(result) | |
| else: | |
| st.warning("Command not recognized. Please try a valid command.") | |