Spaces:
Runtime error
Runtime error
Update llmConnect.py
Browse files- llmConnect.py +50 -8
llmConnect.py
CHANGED
|
@@ -6,6 +6,13 @@ import json
|
|
| 6 |
load_dotenv()
|
| 7 |
import csv
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
try:
|
| 11 |
client = genai.Client(api_key=os.getenv('geminiAPI'))
|
|
@@ -13,6 +20,12 @@ except Exception as e:
|
|
| 13 |
print("Error: ", e)
|
| 14 |
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def readSystemInstructions():
|
| 17 |
try:
|
| 18 |
with open('systemInstruction.txt', 'r') as file:
|
|
@@ -38,15 +51,44 @@ def generateSyntheticData(topic:str):
|
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
-
|
| 42 |
-
def addToDataset(topic:str):
|
| 43 |
data = generateSyntheticData(topic)
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
|
| 52 |
if __name__ == "__main__":
|
|
|
|
| 6 |
load_dotenv()
|
| 7 |
import csv
|
| 8 |
|
| 9 |
+
from supabase import create_client, Client
|
| 10 |
+
|
| 11 |
+
url: str = os.environ.get("SUPABASE_URL")
|
| 12 |
+
key: str = os.environ.get("SUPABASE_KEY")
|
| 13 |
+
supabase: Client = create_client(url, key)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
|
| 17 |
try:
|
| 18 |
client = genai.Client(api_key=os.getenv('geminiAPI'))
|
|
|
|
| 20 |
print("Error: ", e)
|
| 21 |
|
| 22 |
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
except Exception as e:
|
| 26 |
+
print("Error: ", e)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
def readSystemInstructions():
|
| 30 |
try:
|
| 31 |
with open('systemInstruction.txt', 'r') as file:
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
+
def addToDataset(topic: str):
|
|
|
|
| 55 |
data = generateSyntheticData(topic)
|
| 56 |
+
if not data:
|
| 57 |
+
print("Failed to generate data")
|
| 58 |
+
return
|
| 59 |
+
|
| 60 |
+
try:
|
| 61 |
+
with open('dataset.csv', 'w', newline='') as file:
|
| 62 |
+
writer = csv.writer(file)
|
| 63 |
+
for i in data:
|
| 64 |
+
for question_number, question_details in i.items():
|
| 65 |
+
row = [
|
| 66 |
+
question_number,
|
| 67 |
+
question_details['question'],
|
| 68 |
+
question_details['options'][0],
|
| 69 |
+
question_details['options'][1],
|
| 70 |
+
question_details['options'][2],
|
| 71 |
+
question_details['options'][3],
|
| 72 |
+
question_details['correct_choice']
|
| 73 |
+
]
|
| 74 |
+
writer.writerow(row)
|
| 75 |
+
|
| 76 |
+
try:
|
| 77 |
+
supabase.table("quizQuestions").insert({
|
| 78 |
+
"topic": topic,
|
| 79 |
+
"question": question_details['question'],
|
| 80 |
+
"choice-1": question_details['options'][0],
|
| 81 |
+
"choice-2": question_details['options'][1],
|
| 82 |
+
"choice-3": question_details['options'][2],
|
| 83 |
+
"choice-4": question_details['options'][3],
|
| 84 |
+
"correctChoice": question_details['correct_choice']
|
| 85 |
+
}).execute()
|
| 86 |
+
except Exception as e:
|
| 87 |
+
print(f"Error inserting to Supabase: {e}")
|
| 88 |
+
|
| 89 |
+
print("Added to dataset successfully")
|
| 90 |
+
except Exception as e:
|
| 91 |
+
print(f"Error writing to CSV: {e}")
|
| 92 |
|
| 93 |
|
| 94 |
if __name__ == "__main__":
|