mertbozkurt commited on
Commit
a3fc548
·
1 Parent(s): 3b213d5

Add application file

Browse files
Dockerfile CHANGED
@@ -10,4 +10,4 @@ WORKDIR /
10
  # Install requirements.txt
11
  RUN pip install --no-cache-dir --upgrade -r /requirements.txt
12
 
13
- CMD ["uvicorn", "fastapi-den:app", "--host", "0.0.0.0", "--port", "7860"]
 
10
  # Install requirements.txt
11
  RUN pip install --no-cache-dir --upgrade -r /requirements.txt
12
 
13
+ CMD ["gunicorn", "-b", "0.0.0.0:7860", "flask-api:app"]
__pycache__/fastapi-den.cpython-312.pyc CHANGED
Binary files a/__pycache__/fastapi-den.cpython-312.pyc and b/__pycache__/fastapi-den.cpython-312.pyc differ
 
fastapi-den.py CHANGED
@@ -2,8 +2,8 @@ from fastapi import FastAPI, UploadFile, File
2
  from fastapi.responses import JSONResponse
3
  import shutil
4
  import os
5
- import application
6
- import functions
7
  #fotograf ozellikleri
8
  heightImg = 300*4
9
  widthImg = 210*4
@@ -11,6 +11,7 @@ widthImg = 210*4
11
  questions=25
12
  choices=6
13
 
 
14
  a1 = functions.read_answers("answers/test1-1.txt")
15
  a2 = functions.answers2numbers(a1)
16
 
@@ -39,7 +40,7 @@ async def upload_image(image: UploadFile = File(...)):
39
  shutil.copyfileobj(image.file, buffer)
40
 
41
  # Process the uploaded image (you can replace this with your processing function)
42
- result = application.optic1(ans_txt1=a2,
43
  ans_txt2=a4,
44
  ans_txt3=a6,
45
  ans_txt4=a8,
 
2
  from fastapi.responses import JSONResponse
3
  import shutil
4
  import os
5
+ from application import *
6
+ from functions import *
7
  #fotograf ozellikleri
8
  heightImg = 300*4
9
  widthImg = 210*4
 
11
  questions=25
12
  choices=6
13
 
14
+
15
  a1 = functions.read_answers("answers/test1-1.txt")
16
  a2 = functions.answers2numbers(a1)
17
 
 
40
  shutil.copyfileobj(image.file, buffer)
41
 
42
  # Process the uploaded image (you can replace this with your processing function)
43
+ result = optic1(ans_txt1=a2,
44
  ans_txt2=a4,
45
  ans_txt3=a6,
46
  ans_txt4=a8,
flask-api.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import shutil
3
+ import os
4
+ from werkzeug.utils import secure_filename
5
+ from application import *
6
+ from functions import *
7
+
8
+ app = Flask(__name__)
9
+
10
+ # Fotoğraf özellikleri
11
+ heightImg = 300 * 4
12
+ widthImg = 210 * 4
13
+ questions = 25
14
+ choices = 6
15
+
16
+ a1 = functions.read_answers("answers/test1-1.txt")
17
+ a2 = functions.answers2numbers(a1)
18
+
19
+ a3 = functions.read_answers("answers/test1-2.txt")
20
+ a4 = functions.answers2numbers(a3)
21
+
22
+ a5 = functions.read_answers("answers/test1-3.txt")
23
+ a6 = functions.answers2numbers(a5)
24
+
25
+ a7 = functions.read_answers("answers/test1-4.txt")
26
+ a8 = functions.answers2numbers(a7)
27
+
28
+ # Upload endpoint
29
+ @app.route('/upload/', methods=['POST'])
30
+ def upload_image():
31
+ try:
32
+ # Upload received file to a directory
33
+ upload_dir = "uploads"
34
+ os.makedirs(upload_dir, exist_ok=True)
35
+ file = request.files['image']
36
+ filename = secure_filename(file.filename)
37
+ file.save(os.path.join(upload_dir, filename))
38
+
39
+ # Process the uploaded image (you can replace this with your processing function)
40
+ result = optic1(
41
+ ans_txt1=a2,
42
+ ans_txt2=a4,
43
+ ans_txt3=a6,
44
+ ans_txt4=a8,
45
+ pathImage=os.path.join(upload_dir, filename)
46
+ )
47
+
48
+ # Return result as JSON
49
+ return jsonify(result)
50
+ except Exception as e:
51
+ return jsonify({"error": str(e)})
52
+
53
+ if __name__ == '__main__':
54
+ app.run(host="0.0.0.0", port=8000)
req.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ url = "http://localhost:8000/upload/" # Flask uygulamasının adresi ve portu
4
+
5
+ # Gönderilecek dosyanın yolu
6
+ dosya_yolu = "test/test1.1.png"
7
+
8
+ # Dosyayı yükleme isteği oluştur
9
+ dosya = {"image": open(dosya_yolu, "rb")}
10
+ cevap = requests.post(url, files=dosya)
11
+
12
+ # Cevabı yazdır
13
+ print(cevap.json())
requirements.txt CHANGED
@@ -1,4 +1,6 @@
1
  annotated-types==0.6.0
 
 
2
  anyio==4.3.0
3
  certifi==2024.2.2
4
  click==8.1.7
 
1
  annotated-types==0.6.0
2
+ flask
3
+ requests
4
  anyio==4.3.0
5
  certifi==2024.2.2
6
  click==8.1.7
uploads/test1.jpeg ADDED