Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
a-mnich committed May 7, 2024
1 parent 8c855fe commit 80f032b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: excalidraw-stack Image Nightly

on:
workflow_dispatch:
push:
branches:
- main
env:
IMAGE_BASE_TAG: git.b0t.at/b0t-at/excalidraw-ai

jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ vars.registry_uri }}
username: ${{ secrets.registry_username }}
password: ${{ secrets.registry_password }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.IMAGE_BASE_TAG }}:latest
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Verwenden Sie ein offizielles Python-Laufzeitbild als Elternbild
FROM python:3.8-slim-buster

# Setzen Sie die Arbeitsumgebung im Container auf /app
WORKDIR /app

# Kopieren Sie die aktuellen Verzeichnisinhalte in das Arbeitsverzeichnis /app im Container
ADD . /app

# Installieren Sie alle benötigten Pakete
RUN pip install --no-cache-dir -r requirements.txt

# Machen Sie den Port 5000 des Containers verfügbar für die Welt außerhalb dieses Containers
EXPOSE 5000

# Führen Sie app.py aus, wenn der Container gestartet wird
CMD ["python", "app.py"]
27 changes: 27 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from flask import Flask, request, jsonify
from flask_cors import CORS
import os
import openai

app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": os.getenv('ALLOWED_HOST')}})

@app.route('/v1/ai/text-to-diagram/generate', methods=['POST'])
def generate_diagram():
data = request.get_json()
prompt = data.get('prompt', '')

# Call the OpenAI API
response = openai.ChatCompletion.create(
model="gpt-4-1106-preview",
messages=[
{"role": "system", "content": "Translate the following user prompt into a diagram."},
{"role": "user", "content": prompt},
],
)

messages = response['choices'][0]['message']
return jsonify({"generatedResponse": ''.join(message['content'] for message in messages)})

if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker build -t my-python-app .
docker run -p 5000:5000 -e ALLOWED_HOST='http://mein-zugelassener-host.com' my-python-app
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flask
flask_cors
openai

0 comments on commit 80f032b

Please sign in to comment.