mateoluksenberg commited on
Commit
d2bbaf7
1 Parent(s): 907e68e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -1
app.py CHANGED
@@ -18,7 +18,18 @@ async def classify_image(file: UploadFile = File(...)):
18
  # Perform image classification
19
  result = pipe(image)
20
 
21
- return {"classification_result": result[0]} # Return the top prediction
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  except Exception as e:
24
  # Handle exceptions, for example: file not found, image format issues, etc.
@@ -31,6 +42,56 @@ async def home():
31
  <html>
32
  <head>
33
  <title>Image Classification</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  </head>
35
  <body>
36
  <h1>Upload an Image for Classification</h1>
 
18
  # Perform image classification
19
  result = pipe(image)
20
 
21
+ # Add an additional comment to the top result
22
+ additional_comment = " - This is the classification result."
23
+ result_with_comment = {
24
+ "label": result[0]['label'],
25
+ "score": result[0]['score'],
26
+ "comment": additional_comment
27
+ }
28
+
29
+ # Overall result summary
30
+ overall_result = "All results: " + str(result)
31
+
32
+ return {"classification_result": result_with_comment, "overall_result": overall_result} # Return the top prediction with comment and overall summary
33
 
34
  except Exception as e:
35
  # Handle exceptions, for example: file not found, image format issues, etc.
 
42
  <html>
43
  <head>
44
  <title>Image Classification</title>
45
+ <style>
46
+ body {
47
+ font-family: Arial, sans-serif;
48
+ background-color: #f0f0f0;
49
+ margin: 0;
50
+ padding: 0;
51
+ display: flex;
52
+ justify-content: center;
53
+ align-items: center;
54
+ height: 100vh;
55
+ flex-direction: column;
56
+ }
57
+ h1 {
58
+ color: #333;
59
+ }
60
+ form {
61
+ margin: 20px 0;
62
+ padding: 20px;
63
+ background: #fff;
64
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
65
+ border-radius: 8px;
66
+ }
67
+ input[type="file"] {
68
+ margin-bottom: 10px;
69
+ }
70
+ button {
71
+ background-color: #4CAF50;
72
+ color: white;
73
+ border: none;
74
+ padding: 10px 20px;
75
+ text-align: center;
76
+ text-decoration: none;
77
+ display: inline-block;
78
+ font-size: 16px;
79
+ border-radius: 5px;
80
+ cursor: pointer;
81
+ }
82
+ button:hover {
83
+ background-color: #45a049;
84
+ }
85
+ #result {
86
+ margin-top: 20px;
87
+ padding: 20px;
88
+ background: #fff;
89
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
90
+ border-radius: 8px;
91
+ max-width: 500px;
92
+ word-wrap: break-word;
93
+ }
94
+ </style>
95
  </head>
96
  <body>
97
  <h1>Upload an Image for Classification</h1>