Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile +14 -0
- main.py +137 -0
- requirements.txt +6 -0
Dockerfile
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
+
# you will also find guides on how best to write your Dockerfile
|
3 |
+
|
4 |
+
FROM python:3.9
|
5 |
+
|
6 |
+
WORKDIR /code
|
7 |
+
|
8 |
+
COPY ./requirements.txt /code/requirements.txt
|
9 |
+
|
10 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
11 |
+
|
12 |
+
COPY . .
|
13 |
+
|
14 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gspread
|
2 |
+
from google.oauth2.service_account import Credentials
|
3 |
+
from google.auth.exceptions import GoogleAuthError
|
4 |
+
from google.colab import userdata
|
5 |
+
|
6 |
+
# Define chapter categories
|
7 |
+
physics_chapters = {
|
8 |
+
"physics and measurement", "kinematics", "laws of motion", "work energy and power", "rotational motion",
|
9 |
+
"gravitation", "properties of solids and liquids", "thermodynamics", "kinetic theory of gases",
|
10 |
+
"oscillations and waves", "electrostatics", "current electricity",
|
11 |
+
"magnetic effects of current and magnetism", "electromagnetic inductions", "alternating currents",
|
12 |
+
"electromagnetic waves", "optics", "dual nature of matter and radiation", "atoms and nuclei",
|
13 |
+
"electronic devices"
|
14 |
+
}
|
15 |
+
|
16 |
+
chemistry_chapters = {
|
17 |
+
"some basic concepts in chemistry", "atomic structure", "chemical bonding and molecular structure",
|
18 |
+
"chemical thermodynamics", "solutions", "equilibrium", "redox reactions and electrochemistry",
|
19 |
+
"chemical kinetics", "classifications of elements and periodicity in properties", "p-block elements",
|
20 |
+
"d and f-block elements", "coordination compounds", "purifications and charecterisation of organic compounds",
|
21 |
+
"some basic principles of organic chemistry", "hydrocarbons", "organic compounds containing halogens",
|
22 |
+
"organic compounds containing oxygen", "organic compounds containing nitrogen", "biomolecules"
|
23 |
+
}
|
24 |
+
|
25 |
+
maths_chapters = {
|
26 |
+
"Sets, Relation and Functions", "complex numbers and quadratic equations", "matrices and determinants",
|
27 |
+
"permutations and combinations", "binomial theorem", "sequence and series", "limits continuity and differentiability",
|
28 |
+
"integral calculus", "Diffrential Equations", "coordinate geometry", "straight lines", "circle and conic sections",
|
29 |
+
"three dimensional geometry", "vector algebra", "statistics and probability", "trigonometry"
|
30 |
+
}
|
31 |
+
|
32 |
+
# Define base class for chapters
|
33 |
+
class Chapter:
|
34 |
+
def __init__(self):
|
35 |
+
self.data = {}
|
36 |
+
|
37 |
+
def add_marks(self, chapter_name, marks):
|
38 |
+
if chapter_name not in self.data:
|
39 |
+
self.data[chapter_name] = {"sum_marks": 0, "count": 0}
|
40 |
+
self.data[chapter_name]["sum_marks"] += marks
|
41 |
+
self.data[chapter_name]["count"] += 1
|
42 |
+
|
43 |
+
def print_averages(self):
|
44 |
+
for chapter, stats in self.data.items():
|
45 |
+
if stats["count"] > 0:
|
46 |
+
avg = stats["sum_marks"] / stats["count"]
|
47 |
+
print(f"{chapter}: Average = {round(avg, 1)}")
|
48 |
+
|
49 |
+
# Create specific classes for Physics, Chemistry, and Mathematics
|
50 |
+
class PhysicsChapter(Chapter):
|
51 |
+
pass
|
52 |
+
|
53 |
+
class ChemistryChapter(Chapter):
|
54 |
+
pass
|
55 |
+
|
56 |
+
class MathsChapter(Chapter):
|
57 |
+
pass
|
58 |
+
|
59 |
+
# Function to fetch the credentials from environment variables or manually inputted credentials in Colab
|
60 |
+
def get_credentials_from_env():
|
61 |
+
service_account_info = {
|
62 |
+
"type": userdata.get("SERVICE_ACCOUNT_TYPE"),
|
63 |
+
"project_id": userdata.get("PROJECT_ID"),
|
64 |
+
"private_key_id": userdata.get("PRIVATE_KEY_ID"),
|
65 |
+
"private_key": userdata.get("PRIVATE_KEY").replace('\\n', '\n'),
|
66 |
+
"client_email": userdata.get("CLIENT_EMAIL"),
|
67 |
+
"client_id": userdata.get("CLIENT_ID"),
|
68 |
+
"auth_uri": userdata.get("AUTH_URI"),
|
69 |
+
"token_uri": userdata.get("TOKEN_URI"),
|
70 |
+
"auth_provider_x509_cert_url": userdata.get("AUTH_PROVIDER_X509_CERT_URL"),
|
71 |
+
"client_x509_cert_url": userdata.get("CLIENT_X509_CERT_URL"),
|
72 |
+
"universe_domain": userdata.get("UNIVERSE_DOMAIN")
|
73 |
+
}
|
74 |
+
|
75 |
+
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
|
76 |
+
creds = Credentials.from_service_account_info(service_account_info, scopes=scope)
|
77 |
+
return creds
|
78 |
+
|
79 |
+
# Main function to analyze chapter averages
|
80 |
+
def analyze_chapter_averages():
|
81 |
+
try:
|
82 |
+
# Set up credentials
|
83 |
+
creds = get_credentials_from_env()
|
84 |
+
client = gspread.authorize(creds)
|
85 |
+
|
86 |
+
# Open the Google Sheet (replace with your sheet URL)
|
87 |
+
sheet = client.open_by_url('https://docs.google.com/spreadsheets/d/13PUHySUXWtKBusjugoe7Dbsm39PwBUfG4tGLipspIx4/edit?gid=0#gid=0').worksheet('Sheet1')
|
88 |
+
|
89 |
+
# Get all values from the sheet
|
90 |
+
data = sheet.get_all_values()
|
91 |
+
|
92 |
+
# Initialize objects for each subject
|
93 |
+
physics_tracker = PhysicsChapter()
|
94 |
+
chemistry_tracker = ChemistryChapter()
|
95 |
+
maths_tracker = MathsChapter()
|
96 |
+
|
97 |
+
# Iterate over each row in the data
|
98 |
+
for row in data[1:]: # Assuming the first row is headers
|
99 |
+
user_id = row[0] # First column is user_id
|
100 |
+
i = 1
|
101 |
+
while i < len(row):
|
102 |
+
chapter_name = row[i]
|
103 |
+
|
104 |
+
# Ensure chapter_name is a string and marks are valid numbers
|
105 |
+
if isinstance(chapter_name, str):
|
106 |
+
chapter_name = chapter_name.strip().lower()
|
107 |
+
marks = row[i + 1]
|
108 |
+
|
109 |
+
if marks and marks.replace('.', '', 1).isdigit(): # Check if marks is a valid number
|
110 |
+
marks = float(marks)
|
111 |
+
# Check if the chapter belongs to Physics, Chemistry, or Maths
|
112 |
+
if chapter_name in physics_chapters:
|
113 |
+
physics_tracker.add_marks(chapter_name, marks)
|
114 |
+
elif chapter_name in chemistry_chapters:
|
115 |
+
chemistry_tracker.add_marks(chapter_name, marks)
|
116 |
+
elif chapter_name in maths_chapters:
|
117 |
+
maths_tracker.add_marks(chapter_name, marks)
|
118 |
+
|
119 |
+
i += 2 # Move to the next chapter and marks
|
120 |
+
|
121 |
+
# Print average marks per chapter for each subject
|
122 |
+
print("Physics Chapters:")
|
123 |
+
physics_tracker.print_averages()
|
124 |
+
print("\nChemistry Chapters:")
|
125 |
+
chemistry_tracker.print_averages()
|
126 |
+
print("\nMaths Chapters:")
|
127 |
+
maths_tracker.print_averages()
|
128 |
+
|
129 |
+
except GoogleAuthError as e:
|
130 |
+
print(f"Authentication error: {e}")
|
131 |
+
except gspread.exceptions.SpreadsheetNotFound:
|
132 |
+
print("Spreadsheet not found. Please check the URL.")
|
133 |
+
except Exception as e:
|
134 |
+
print(f"An error occurred: {e}")
|
135 |
+
|
136 |
+
# Call the main function
|
137 |
+
analyze_chapter_averages()
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
google-auth
|
4 |
+
google-auth-oauthlib
|
5 |
+
google-auth-httplib2
|
6 |
+
gspread
|