Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,24 +7,23 @@ import cohere
|
|
| 7 |
# Load environment variables
|
| 8 |
load_dotenv(verbose=True)
|
| 9 |
|
| 10 |
-
# Establish database connection
|
| 11 |
-
conn = mysql.connector.connect(
|
| 12 |
-
host=os.environ.get("HOST"),
|
| 13 |
-
user=os.environ.get("USER_NAME"),
|
| 14 |
-
password=os.environ.get("PASSWORD"),
|
| 15 |
-
port=os.environ.get("PORT"),
|
| 16 |
-
database=os.environ.get("DB"),
|
| 17 |
-
ssl_disabled=True
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
cursor = conn.cursor(dictionary=True)
|
| 21 |
-
|
| 22 |
# Function to fetch top high performers
|
| 23 |
#def get_top_high_performers(html: str):
|
| 24 |
def get_top_high_performers(html: str, limit: str):
|
| 25 |
|
| 26 |
#cursor = conn.cursor(dictionary=True)
|
| 27 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
with cursor:
|
| 29 |
# Query to fetch top performers based on calculated score
|
| 30 |
query = f"""
|
|
@@ -71,6 +70,10 @@ def get_top_high_performers(html: str, limit: str):
|
|
| 71 |
final = res.message.content[0].text
|
| 72 |
|
| 73 |
return "\n\n".join(formatted_results),final
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
except Exception as e:
|
| 76 |
return f"Error occurred: {e}","Error"
|
|
|
|
| 7 |
# Load environment variables
|
| 8 |
load_dotenv(verbose=True)
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Function to fetch top high performers
|
| 11 |
#def get_top_high_performers(html: str):
|
| 12 |
def get_top_high_performers(html: str, limit: str):
|
| 13 |
|
| 14 |
#cursor = conn.cursor(dictionary=True)
|
| 15 |
try:
|
| 16 |
+
# Establish database connection
|
| 17 |
+
conn = mysql.connector.connect(
|
| 18 |
+
host=os.environ.get("HOST"),
|
| 19 |
+
user=os.environ.get("USER_NAME"),
|
| 20 |
+
password=os.environ.get("PASSWORD"),
|
| 21 |
+
port=os.environ.get("PORT"),
|
| 22 |
+
database=os.environ.get("DB"),
|
| 23 |
+
ssl_disabled=True
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
cursor = conn.cursor(dictionary=True)
|
| 27 |
with cursor:
|
| 28 |
# Query to fetch top performers based on calculated score
|
| 29 |
query = f"""
|
|
|
|
| 70 |
final = res.message.content[0].text
|
| 71 |
|
| 72 |
return "\n\n".join(formatted_results),final
|
| 73 |
+
finally:
|
| 74 |
+
# リソースを解放
|
| 75 |
+
cursor.close()
|
| 76 |
+
conn.close()
|
| 77 |
|
| 78 |
except Exception as e:
|
| 79 |
return f"Error occurred: {e}","Error"
|