gurwindersingh commited on
Commit
2b4a005
·
1 Parent(s): 832ddd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -12
app.py CHANGED
@@ -1,20 +1,58 @@
1
  import streamlit as st
2
- from transformers import pipeline
 
 
 
 
3
  from PIL import Image
4
 
5
- pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
 
6
 
7
- st.title("Hot Dog? Or Not?")
8
 
9
- file_name = st.file_uploader("Upload a hot dog candidate image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- if file_name is not None:
12
- col1, col2 = st.columns(2)
13
 
14
- image = Image.open(file_name)
15
- col1.image(image, use_column_width=True)
16
- predictions = pipeline(image)
 
 
17
 
18
- col2.header("Probabilities")
19
- for p in predictions:
20
- col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import seaborn as sns
3
+ import matplotlib.pyplot as plt
4
+ import os, random
5
+ import cv2
6
+ from tensorflow.keras.models import load_model
7
  from PIL import Image
8
 
9
+ def main():
10
+ st.title('Sudoku Solver')
11
 
12
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
13
 
14
+ if uploaded_file is not None:
15
+ # Importing puzzle to be solved
16
+ puzzle = cv2.imread(uploaded_file)
17
+
18
+ # Resizing puzzle to be solved
19
+ puzzle = cv2.resize(puzzle, (450,450))
20
+ # Preprocessing Puzzle
21
+ su_puzzle = preprocess(puzzle)
22
+
23
+ # Finding the outline of the sudoku puzzle in the image
24
+ su_contour_1= su_puzzle.copy()
25
+ su_contour_2= sudoku_a.copy()
26
+ su_contour, hierarchy = cv2.findContours(su_puzzle,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
27
+ cv2.drawContours(su_contour_1, su_contour,-1,(0,255,0),3)
28
+
29
+ black_img = np.zeros((450,450,3), np.uint8)
30
+ su_biggest, su_maxArea = main_outline(su_contour)
31
+ if su_biggest.size != 0:
32
+ su_biggest = reframe(su_biggest)
33
+ cv2.drawContours(su_contour_2,su_biggest,-1, (0,255,0),10)
34
+ su_pts1 = np.float32(su_biggest)
35
+ su_pts2 = np.float32([[0,0],[450,0],[0,450],[450,450]])
36
+ su_matrix = cv2.getPerspectiveTransform(su_pts1,su_pts2)
37
+ su_imagewrap = cv2.warpPerspective(puzzle,su_matrix,(450,450))
38
+ su_imagewrap =cv2.cvtColor(su_imagewrap, cv2.COLOR_BGR2GRAY)
39
 
40
+ sudoku_cell = splitcells(su_imagewrap)
41
+ sudoku_cell_croped= CropCell(sudoku_cell)
42
 
43
+ grid = read_cells(sudoku_cell_croped, model)
44
+ grid = np.asarray(grid)
45
+ grid = np.reshape(grid,(9,9))
46
+ solve(grid)
47
+
48
 
49
+
50
+ # Display the solution or appropriate message
51
+ if solve(grid):
52
+ st.header("Sudoku Solved:")
53
+ st.write(Solved(grid))
54
+ else:
55
+ st.write("No solution found.")
56
+
57
+ if __name__ == '__main__':
58
+ main()