Skip to content

Commit

Permalink
Merge pull request #2 from Ulas-Scan/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
iyoubee authored Jun 8, 2024
2 parents 08069c6 + c97a15a commit a19c65d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 36 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,3 @@ jobs:
run: |
docker build -t $GCP_REGION-docker.pkg.dev/$GCP_PROJECT_ID/ulascan/$APP_NAME:latest .
docker push $GCP_REGION-docker.pkg.dev/$GCP_PROJECT_ID/ulascan/$APP_NAME:latest
deploy:
needs: build
runs-on: ubuntu-latest

steps:
- name: Install SSH client
run: sudo apt-get install -y ssh

- name: Set up SSH
run: |
echo "$SSH_PRIVATE_KEY" > ssh_key
chmod 600 ssh_key
- name: Deploy to GCE
run: |
ssh -o StrictHostKeyChecking=no \
-i ssh_key \
ulascan@$GCE_INSTANCE_IP \
"gcloud --quiet auth configure-docker $GCP_REGION-docker.pkg.dev \
&& docker pull $GCP_REGION-docker.pkg.dev/$GCP_PROJECT_ID/ulascan/$APP_NAME:latest \
&& docker stop $APP_NAME || true \
&& docker rm --force $APP_NAME || true \
&& docker run -d \
--name $APP_NAME \
-p 5000:5000 \
$GCP_REGION-docker.pkg.dev/$GCP_PROJECT_ID/ulascan/$APP_NAME:latest \
&& docker image prune -f"
- name: Cleanup SSH key
run: rm ssh_key
17 changes: 12 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, request
from flask import Flask, request, jsonify
from utils import get_model, get_tokenizer, predict_sentiment

app = Flask(__name__)
Expand All @@ -10,15 +10,22 @@
tokenizer = get_tokenizer(MODEL_NAME)
model = get_model(PRETRAINED_PATH)

@app.route("/predict/", methods=['GET'])
@app.route("/predict", methods=['POST'])
def predict():
statements = request.json.get("statements")
data = request.json
if data is None:
return jsonify({"error": "Invalid JSON"}), 400

statements = data.get("statements")
if statements is None:
return jsonify({"error": "No statements provided"}), 400

# statements: list of reviews
report = {'Positive': 0, 'Negative': 0}
for statement in statements:
sentiment = predict_sentiment(statement, tokenizer, model, MAX_LENGTH)
report[sentiment] += 1
return report
return jsonify(report)

if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)
app.run(host='0.0.0.0', port=5000)

0 comments on commit a19c65d

Please sign in to comment.