Kortikov Mikhail
commited on
Commit
•
e74a3cd
1
Parent(s):
a3d324f
"Add application file"
Browse files- dockerfile +11 -0
- main.py +7 -0
- metadata.json +1 -0
- models/fine_tuned/resnet50_fruit_classification.pth +3 -0
- models/fruit_recognition_model.pth +3 -0
- requirements.txt +6 -0
- templates/index.html +55 -0
dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
COPY ./requirements.txt /code/requirements.txt
|
6 |
+
|
7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
8 |
+
|
9 |
+
COPY . .
|
10 |
+
|
11 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
|
3 |
+
app = FastAPI()
|
4 |
+
|
5 |
+
@app.get("/")
|
6 |
+
def read_root():
|
7 |
+
return {"Hello": "World!"}
|
metadata.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"classes": ["apple_braeburn_1", "cucumber_1", "pear_1"]}
|
models/fine_tuned/resnet50_fruit_classification.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ab21975ce41b8e353a3ffbae29f1e7a321584ead64b7f13c8db0d061440a5401
|
3 |
+
size 102579565
|
models/fruit_recognition_model.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6fae0b5ba163f4c2f54f3d0c400969b421edf23cfa9c1f129e2ec3e76c7ee173
|
3 |
+
size 44792653
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi==0.74.*
|
2 |
+
requests==2.27.*
|
3 |
+
sentencepiece==0.1.*
|
4 |
+
torch==1.11.*
|
5 |
+
transformers==4.*
|
6 |
+
uvicorn[standard]==0.17.*
|
templates/index.html
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Fruit Recognition App</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
font-family: Arial, sans-serif;
|
10 |
+
}
|
11 |
+
form {
|
12 |
+
display: flex;
|
13 |
+
flex-direction: column;
|
14 |
+
align-items: center;
|
15 |
+
gap: 10px;
|
16 |
+
}
|
17 |
+
#result {
|
18 |
+
font-size: 24px;
|
19 |
+
font-weight: bold;
|
20 |
+
margin-top: 20px;
|
21 |
+
}
|
22 |
+
</style>
|
23 |
+
</head>
|
24 |
+
<body>
|
25 |
+
<h1>Fruit Recognition App</h1>
|
26 |
+
<form id="fruit-form" enctype="multipart/form-data">
|
27 |
+
<label for="image-upload">Choose an image:</label>
|
28 |
+
<input type="file" id="image-upload" name="image" accept="image/*" required>
|
29 |
+
<button type="submit">Recognize Fruit</button>
|
30 |
+
</form>
|
31 |
+
<div id="result"></div>
|
32 |
+
|
33 |
+
<script>
|
34 |
+
const form = document.getElementById('fruit-form');
|
35 |
+
const resultDiv = document.getElementById('result');
|
36 |
+
|
37 |
+
form.addEventListener('submit', async (e) => {
|
38 |
+
e.preventDefault();
|
39 |
+
|
40 |
+
const formData = new FormData(form);
|
41 |
+
const response = await fetch('/predict/', {
|
42 |
+
method: 'POST',
|
43 |
+
body: formData
|
44 |
+
});
|
45 |
+
|
46 |
+
if (response.ok) {
|
47 |
+
const data = await response.json();
|
48 |
+
resultDiv.textContent = `Recognized Fruit: ${data.predicted_class}`;
|
49 |
+
} else {
|
50 |
+
resultDiv.textContent = 'Error: Unable to recognize fruit.';
|
51 |
+
}
|
52 |
+
});
|
53 |
+
</script>
|
54 |
+
</body>
|
55 |
+
</html>
|