Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,95 +21,7 @@ description = """
|
|
21 |
Please give it 4 to 5 minutes for the model to load and Run , consider using Python code with less than 120 lines of code due to GPU constrainst
|
22 |
"""
|
23 |
css = """.toast-wrap { display: none !important } """
|
24 |
-
examples=[
|
25 |
-
import sys
|
26 |
-
import os
|
27 |
-
import someDatabaseLib
|
28 |
-
|
29 |
-
# Global variables
|
30 |
-
config = {"db": "localhost", "user": "admin", "password": "admin"}
|
31 |
-
connection = None
|
32 |
-
|
33 |
-
def dbConnect():
|
34 |
-
global connection
|
35 |
-
try:
|
36 |
-
connection = someDatabaseLib.connect(config["db"], config["user"], config["password"])
|
37 |
-
except Exception as e:
|
38 |
-
print(e)
|
39 |
-
sys.exit(1)
|
40 |
-
|
41 |
-
def fetchData():
|
42 |
-
global connection
|
43 |
-
if connection is None:
|
44 |
-
print("Not connected to DB")
|
45 |
-
return None
|
46 |
-
try:
|
47 |
-
cursor = connection.cursor()
|
48 |
-
cursor.execute("SELECT * FROM someTable WHERE someColumn='someValue'")
|
49 |
-
return cursor.fetchall()
|
50 |
-
except Exception as e:
|
51 |
-
print("Failed to fetch data: ", e)
|
52 |
-
return None
|
53 |
-
|
54 |
-
def processData(data):
|
55 |
-
if data is None:
|
56 |
-
print("No data provided")
|
57 |
-
return None
|
58 |
-
result = []
|
59 |
-
for row in data:
|
60 |
-
# Processing logic here
|
61 |
-
result.append(row)
|
62 |
-
return result
|
63 |
-
|
64 |
-
def main():
|
65 |
-
dbConnect()
|
66 |
-
data = fetchData()
|
67 |
-
if data is None:
|
68 |
-
print("No data fetched")
|
69 |
-
sys.exit(1)
|
70 |
-
processedData = processData(data)
|
71 |
-
print("Data processed")
|
72 |
-
|
73 |
-
if __name__ == "__main__":
|
74 |
-
main()
|
75 |
-
|
76 |
-
# Additional functions and logic mixed together without clear separation or modularisation
|
77 |
-
def someOtherFunction():
|
78 |
-
pass
|
79 |
-
|
80 |
-
# Hardcoded paths and configuration details
|
81 |
-
path_to_files = "/path/to/some/files"
|
82 |
-
for file_name in os.listdir(path_to_files):
|
83 |
-
with open(os.path.join(path_to_files, file_name), 'r') as file:
|
84 |
-
data = file.read()
|
85 |
-
# Do something with the data
|
86 |
-
|
87 |
-
# Poor error handling and mixing of concerns (e.g., UI logic with business logic)
|
88 |
-
def userInterfaceFunction():
|
89 |
-
choice = input("Enter your choice: ")
|
90 |
-
if choice == "1":
|
91 |
-
print("User chose 1")
|
92 |
-
# Proceed with option 1
|
93 |
-
elif choice == "2":
|
94 |
-
print("User chose 2")
|
95 |
-
# Proceed with option 2
|
96 |
-
else:
|
97 |
-
print("Invalid choice")
|
98 |
-
|
99 |
-
# Direct database access mixed with business logic without any abstraction layer
|
100 |
-
def directDBAccess():
|
101 |
-
global config
|
102 |
-
try:
|
103 |
-
conn = someDatabaseLib.connect(config["db"], config["user"], config["password"])
|
104 |
-
cursor = conn.cursor()
|
105 |
-
cursor.execute("UPDATE someTable SET someColumn='newValue' WHERE anotherColumn='value'")
|
106 |
-
except Exception as e:
|
107 |
-
print("Database operation failed: ", e)
|
108 |
-
|
109 |
-
# Mixing of different levels of abstraction, lack of consistent error handling, and no use of classes or functions to encapsulate related operations
|
110 |
-
|
111 |
-
"""] ,
|
112 |
-
["""
|
113 |
def analyze_sales_data(sales_records):
|
114 |
active_sales = filter(lambda record: record['status'] == 'active', sales_records)
|
115 |
sales_by_category = {}
|
|
|
21 |
Please give it 4 to 5 minutes for the model to load and Run , consider using Python code with less than 120 lines of code due to GPU constrainst
|
22 |
"""
|
23 |
css = """.toast-wrap { display: none !important } """
|
24 |
+
examples=[ ["""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
def analyze_sales_data(sales_records):
|
26 |
active_sales = filter(lambda record: record['status'] == 'active', sales_records)
|
27 |
sales_by_category = {}
|