isurulkh commited on
Commit
84d6711
1 Parent(s): d7cd489

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +69 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ from google.generativeai import Client
4
+ import os
5
+ from rubik_solver import Solver
6
+
7
+ # API Key setup
8
+ os.environ["GOOGLE_API_KEY"] = "AIzaSyCttG4s8Tue8RpSb2mK1tvkJSp17YETGGk" # Replace with your actual API key
9
+ client = Client()
10
+
11
+ # App title and instructions
12
+ st.title("Rubik's Cube Solver")
13
+ st.write("Upload images of each cube face for solution.")
14
+
15
+ # Uploaders for each face
16
+ face_images = [st.file_uploader("Face {}".format(i+1)) for i in range(6)]
17
+
18
+ # Submit button
19
+ submit_button = st.button("Solve Cube!")
20
+
21
+ if submit_button:
22
+ try:
23
+ if all(face_images):
24
+ cube_state = []
25
+ for face in face_images:
26
+ # Read image
27
+ image = cv2.imdecode(np.fromstring(face.read(), np.uint8), cv2.IMREAD_UNCHANGED)
28
+
29
+ # Use Gemini Pro API for color detection
30
+ response = client.generate_text(
31
+ prompt="Identify the colors on this Rubik's cube face",
32
+ image=image,
33
+ model="gemini-pro-vision"
34
+ )
35
+ colors = response.text.splitlines() # Parse response for colors
36
+
37
+ # Add face colors to cube state
38
+ cube_state.append(colors)
39
+
40
+ # Check for successful color detection
41
+ if all(cube_state):
42
+ st.write("Colors detected! Solving...")
43
+ else:
44
+ st.error("Some faces had errors! Retry with clear images.")
45
+ else:
46
+ st.error("Please upload all 6 face images.")
47
+
48
+ if all(cube_state):
49
+ # Create solver object
50
+ solver = Solver(cube_state)
51
+
52
+ # Solve the cube and get moves
53
+ solution = solver.solve()
54
+
55
+ # Display solution steps
56
+ st.write("Solution:")
57
+ for step, move in enumerate(solution, start=1):
58
+ st.write(f"Step {step}: {move}")
59
+
60
+ # Use animation or visuals to guide user (optional)
61
+
62
+ # Allow user to proceed step-by-step
63
+ if not st.button(f"Next Step ({step}/{len(solution)})"):
64
+ break
65
+
66
+ st.success("Cube solved!")
67
+
68
+ except Exception as e:
69
+ st.error("An error occurred: {}".format(e))
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ opencv-python
3
+ rubik-solver
4
+ google-generativeai