Clean up the code.

This commit is contained in:
Cristiano Ferreira
2024-04-10 22:21:30 +01:00
parent f1d2ec3bf8
commit 6e2355ee4c
24 changed files with 36 additions and 6397 deletions

View File

@@ -16,9 +16,6 @@ class QuestionType(Enum):
READING_PASSAGE_2 = "Reading Passage 2"
READING_PASSAGE_3 = "Reading Passage 3"
class ExerciseType(Enum):
MULTIPLE_CHOICE = "multiple choice"
def get_grading_messages(question_type: QuestionType, question: str, answer: str, context: str = None):
if QuestionType.WRITING_TASK_1 == question_type:

View File

@@ -3,4 +3,4 @@ from enum import Enum
class ExamVariant(Enum):
FULL = "full"
PARTIAL = "partial"
PARTIAL = "partial"

View File

@@ -1,17 +1,17 @@
import queue
import string
import nltk
import random
import re
import string
import uuid
import nltk
from wonderwords import RandomWord
from helper.api_messages import QuestionType
from helper.constants import *
from helper.firebase_helper import get_all
from helper.openai_interface import make_openai_instruct_call, make_openai_call
from helper.token_counter import count_tokens
from helper.constants import *
from wonderwords import RandomWord
nltk.download('words')
@@ -84,6 +84,7 @@ def gen_reading_passage_3(topic, req_exercises, difficulty):
"difficulty": difficulty
}
def divide_number_into_parts(number, parts):
if number < parts:
return None

View File

@@ -1,5 +1,5 @@
import os
import datetime
import os
from pathlib import Path
@@ -12,6 +12,6 @@ def delete_files_older_than_one_day(directory):
file_name = file_path.name
file_modified_time = datetime.datetime.fromtimestamp(file_path.stat().st_mtime)
time_difference = current_time - file_modified_time
if time_difference.days > 1 and "placeholder" not in file_name:
if time_difference.days > 1 and "placeholder" not in file_name:
file_path.unlink()
print(f"Deleted file: {file_path}")
print(f"Deleted file: {file_path}")

View File

@@ -1,15 +1,7 @@
import logging
from firebase_admin import firestore
from google.cloud import storage
import os
import uuid
import firebase_admin
from firebase_admin import credentials, firestore
from dotenv import load_dotenv
import app
def download_firebase_file(bucket_name, source_blob_name, destination_file_name):
@@ -21,6 +13,7 @@ def download_firebase_file(bucket_name, source_blob_name, destination_file_name)
logging.info(f"File uploaded to {destination_file_name}")
return destination_file_name
def upload_file_firebase(bucket_name, destination_blob_name, source_file_name):
# Uploads a file to Firebase Storage.
storage_client = storage.Client()
@@ -31,9 +24,11 @@ def upload_file_firebase(bucket_name, destination_blob_name, source_file_name):
logging.info(f"File uploaded to {destination_blob_name}")
return True
except Exception as e:
import app
app.app.logger.error("Error uploading file to Google Cloud Storage: " + str(e))
return False
def upload_file_firebase_get_url(bucket_name, destination_blob_name, source_file_name):
# Uploads a file to Firebase Storage.
storage_client = storage.Client()
@@ -50,9 +45,11 @@ def upload_file_firebase_get_url(bucket_name, destination_blob_name, source_file
url = blob.public_url
return url
except Exception as e:
import app
app.app.logger.error("Error uploading file to Google Cloud Storage: " + str(e))
return None
def save_to_db(collection: str, item):
db = firestore.client()
collection_ref = db.collection(collection)
@@ -77,6 +74,7 @@ def save_to_db_with_id(collection: str, item, id: str):
else:
return (False, None)
def get_all(collection: str):
db = firestore.client()
collection_ref = db.collection(collection)
@@ -87,4 +85,3 @@ def get_all(collection: str):
)
return all_exercises

View File

@@ -1,6 +1,6 @@
import jwt
import os
import jwt
from dotenv import load_dotenv
load_dotenv()

View File

@@ -1,10 +1,8 @@
import logging
import os
import random
import requests
import time
import requests
from dotenv import load_dotenv
import app
@@ -29,14 +27,6 @@ GET_HEADER = {
'X-Api-Key': TOKEN
}
MATTHEW_NOAH = "11b234e504e44bfda9bc6b7aac3c8f81"
VERA_CERISE = "9bf2f27009cd403ab4ba4e22629b27bb"
EDWARD_TONY = "d3333e37952946059b45efc8482a2b6c"
TANYA_MOLLY = "07c75076b3f94df4ac658c6de72be83a"
KAYLA_ABBI = "d688099f8db9472cb4890b0561e81793"
JEROME_RYAN = "ad41feb2a5c4483085525e3d8907f512"
TYLER_CHRISTOPHER = "03c796f8ed274bb38f19e893bcbc6121"
def create_videos_and_save_to_db(exercises, template, id):
# Speaking 1
@@ -118,6 +108,7 @@ def create_videos_and_save_to_db(exercises, template, id):
save_to_db_with_id("speaking", template, id)
app.app.logger.info('Saved speaking to DB with id ' + id + " : " + str(template))
def create_video(text, avatar):
# POST TO CREATE VIDEO
create_video_url = 'https://api.heygen.com/v2/template/' + avatar + '/generate'

View File

@@ -1,8 +1,8 @@
import json
import openai
import os
import re
import openai
from dotenv import load_dotenv
from helper.constants import GPT_3_5_TURBO_INSTRUCT, BLACKLISTED_WORDS
@@ -16,7 +16,6 @@ TOP_P = 0.9
FREQUENCY_PENALTY = 0.5
TRY_LIMIT = 2
try_count = 0
# GRADING SUMMARY

1238
helper/question_templates.py Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,10 @@
import whisper
import os
import nltk
import boto3
import random
import boto3
import nltk
import whisper
nltk.download('words')
from nltk.corpus import words
from helper.constants import *

View File

@@ -1,5 +1,4 @@
# This is a work in progress. There are still bugs. Once it is production-ready this will become a full repo.
import os
def count_tokens(text, model_name="gpt-3.5-turbo", debug=False):
@@ -86,4 +85,4 @@ class TokenBuffer:
self.buffer = self.buffer.split(" ", removed_tokens)[-1]
def get_buffer(self):
return self.buffer
return self.buffer