Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,116 @@ 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 pandas as pd
|
| 26 |
import re
|
| 27 |
import ast
|
|
@@ -66,28 +175,7 @@ def evaluate_dataframe_multiple_runs(df, runs=3):
|
|
| 66 |
df_metrics_mean = pd.concat(all_results).groupby(level=0).mean()
|
| 67 |
df_metrics_std = pd.concat(all_results).groupby(level=0).std()
|
| 68 |
return df_metrics_mean, df_metrics_std
|
| 69 |
-
""" ]
|
| 70 |
-
["""
|
| 71 |
-
def analyze_sales_data(sales_records):
|
| 72 |
-
active_sales = filter(lambda record: record['status'] == 'active', sales_records)
|
| 73 |
-
sales_by_category = {}
|
| 74 |
-
for record in active_sales:
|
| 75 |
-
category = record['category']
|
| 76 |
-
total_sales = record['units_sold'] * record['price_per_unit']
|
| 77 |
-
if category not in sales_by_category:
|
| 78 |
-
sales_by_category[category] = {'total_sales': 0, 'total_units': 0}
|
| 79 |
-
sales_by_category[category]['total_sales'] += total_sales
|
| 80 |
-
sales_by_category[category]['total_units'] += record['units_sold']
|
| 81 |
-
average_sales_data = []
|
| 82 |
-
for category, data in sales_by_category.items():
|
| 83 |
-
average_sales = data['total_sales'] / data['total_units']
|
| 84 |
-
sales_by_category[category]['average_sales'] = average_sales
|
| 85 |
-
average_sales_data.append((category, average_sales))
|
| 86 |
-
average_sales_data.sort(key=lambda x: x[1], reverse=True)
|
| 87 |
-
for rank, (category, _) in enumerate(average_sales_data, start=1):
|
| 88 |
-
sales_by_category[category]['rank'] = rank
|
| 89 |
-
return sales_by_category
|
| 90 |
-
"""]]
|
| 91 |
|
| 92 |
|
| 93 |
# Stream text - stream tokens with InferenceClient from TGI
|
|
|
|
| 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 = {}
|
| 116 |
+
for record in active_sales:
|
| 117 |
+
category = record['category']
|
| 118 |
+
total_sales = record['units_sold'] * record['price_per_unit']
|
| 119 |
+
if category not in sales_by_category:
|
| 120 |
+
sales_by_category[category] = {'total_sales': 0, 'total_units': 0}
|
| 121 |
+
sales_by_category[category]['total_sales'] += total_sales
|
| 122 |
+
sales_by_category[category]['total_units'] += record['units_sold']
|
| 123 |
+
average_sales_data = []
|
| 124 |
+
for category, data in sales_by_category.items():
|
| 125 |
+
average_sales = data['total_sales'] / data['total_units']
|
| 126 |
+
sales_by_category[category]['average_sales'] = average_sales
|
| 127 |
+
average_sales_data.append((category, average_sales))
|
| 128 |
+
average_sales_data.sort(key=lambda x: x[1], reverse=True)
|
| 129 |
+
for rank, (category, _) in enumerate(average_sales_data, start=1):
|
| 130 |
+
sales_by_category[category]['rank'] = rank
|
| 131 |
+
return sales_by_category
|
| 132 |
+
"""] ,
|
| 133 |
+
["""
|
| 134 |
import pandas as pd
|
| 135 |
import re
|
| 136 |
import ast
|
|
|
|
| 175 |
df_metrics_mean = pd.concat(all_results).groupby(level=0).mean()
|
| 176 |
df_metrics_std = pd.concat(all_results).groupby(level=0).std()
|
| 177 |
return df_metrics_mean, df_metrics_std
|
| 178 |
+
""" ] ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
|
| 181 |
# Stream text - stream tokens with InferenceClient from TGI
|