diff --git a/Makefile b/Makefile index f4863dc..0e0e0af 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ all: # ------------------------ # start-backend: - @python 'linguaphoto/main.py' + @uvicorn linguaphoto.main:app --reload --port 8080 --host localhost start-frontend: @cd frontend && npm start diff --git a/frontend/src/api/auth.ts b/frontend/src/api/auth.ts index 4c86fa3..0afed43 100644 --- a/frontend/src/api/auth.ts +++ b/frontend/src/api/auth.ts @@ -21,7 +21,9 @@ export const read_me = async (token: string): Promise => { } }; export const signin = async (data: SigninData): Promise => { + console.log("signing in... url:", `${API_URL}/signin`); const response = await axios.post(`${API_URL}/signin`, data); + console.log("signing in... response:", response.data); return response.data; }; export const social_facebook_login = async ( diff --git a/linguaphoto/__init__.py b/linguaphoto/__init__.py index e69de29..f102a9c 100644 --- a/linguaphoto/__init__.py +++ b/linguaphoto/__init__.py @@ -0,0 +1 @@ +__version__ = "0.0.1" diff --git a/linguaphoto/ai/cli.py b/linguaphoto/ai/cli.py index c5a4b95..02a64b9 100644 --- a/linguaphoto/ai/cli.py +++ b/linguaphoto/ai/cli.py @@ -7,8 +7,9 @@ from openai import AsyncOpenAI from PIL import Image -from transcribe import transcribe_image -from tts import synthesize_text + +from linguaphoto.ai.transcribe import transcribe_image +from linguaphoto.ai.tts import synthesize_text logger = logging.getLogger(__name__) diff --git a/linguaphoto/ai/transcribe.py b/linguaphoto/ai/transcribe.py index 9e18f81..5048385 100644 --- a/linguaphoto/ai/transcribe.py +++ b/linguaphoto/ai/transcribe.py @@ -1,17 +1,15 @@ """Uses the OpenAI API to transcribe an image to text.""" -# import argparse - -# import asyncio import base64 import logging from io import BytesIO import aiohttp -from models import TranscriptionResponse from openai import AsyncOpenAI from PIL import Image +from linguaphoto.models import TranscriptionResponse + logger = logging.getLogger(__name__) PROMPT = """ diff --git a/linguaphoto/ai/tts.py b/linguaphoto/ai/tts.py index 33700ec..6ad7e90 100644 --- a/linguaphoto/ai/tts.py +++ b/linguaphoto/ai/tts.py @@ -6,9 +6,10 @@ from pathlib import Path from typing import AsyncIterator -from ai.transcribe import TranscriptionResponse from openai import AsyncOpenAI +from linguaphoto.ai.transcribe import TranscriptionResponse + logger = logging.getLogger(__name__) diff --git a/linguaphoto/api/api.py b/linguaphoto/api/api.py index ad7d47f..a79c4d8 100644 --- a/linguaphoto/api/api.py +++ b/linguaphoto/api/api.py @@ -12,9 +12,10 @@ to handle routing for the entire API. """ -from api import collection, image, subscription, user from fastapi import APIRouter +from linguaphoto.api import collection, image, subscription, user + # Create a new API router router = APIRouter() diff --git a/linguaphoto/api/collection.py b/linguaphoto/api/collection.py index 935a469..dc63ed4 100644 --- a/linguaphoto/api/collection.py +++ b/linguaphoto/api/collection.py @@ -2,12 +2,13 @@ from typing import List -from crud.collection import CollectionCrud -from errors import NotAuthorizedError from fastapi import APIRouter, Depends -from models import Collection -from schemas.collection import CollectionCreateFragment, CollectionEditFragment -from utils.auth import get_current_user_id + +from linguaphoto.crud.collection import CollectionCrud +from linguaphoto.errors import NotAuthorizedError +from linguaphoto.models import Collection +from linguaphoto.schemas.collection import CollectionCreateFragment, CollectionEditFragment +from linguaphoto.utils.auth import get_current_user_id router = APIRouter() diff --git a/linguaphoto/api/image.py b/linguaphoto/api/image.py index 08558b6..8884289 100644 --- a/linguaphoto/api/image.py +++ b/linguaphoto/api/image.py @@ -2,12 +2,13 @@ from typing import Annotated, List -from crud.collection import CollectionCrud -from crud.image import ImageCrud from fastapi import APIRouter, Depends, File, Form, HTTPException, UploadFile -from models import Image from pydantic import BaseModel -from utils.auth import get_current_user_id, subscription_validate + +from linguaphoto.crud.collection import CollectionCrud +from linguaphoto.crud.image import ImageCrud +from linguaphoto.models import Image +from linguaphoto.utils.auth import get_current_user_id, subscription_validate class TranslateFramgement(BaseModel): diff --git a/linguaphoto/api/subscription.py b/linguaphoto/api/subscription.py index 6269538..588a85e 100644 --- a/linguaphoto/api/subscription.py +++ b/linguaphoto/api/subscription.py @@ -1,10 +1,11 @@ """Collection API.""" import stripe -from crud.user import UserCrud from fastapi import APIRouter, Depends, HTTPException -from settings import settings -from utils.auth import get_current_user_id + +from linguaphoto.crud.user import UserCrud +from linguaphoto.settings import settings +from linguaphoto.utils.auth import get_current_user_id router = APIRouter() diff --git a/linguaphoto/api/user.py b/linguaphoto/api/user.py index 8dc3b21..2d6ba55 100644 --- a/linguaphoto/api/user.py +++ b/linguaphoto/api/user.py @@ -2,14 +2,15 @@ from datetime import timedelta -from crud.user import UserCrud from fastapi import APIRouter, Depends, HTTPException -from schemas.user import ( + +from linguaphoto.crud.user import UserCrud +from linguaphoto.schemas.user import ( UserSigninFragment, UserSigninRespondFragment, UserSignupFragment, ) -from utils.auth import create_access_token, decode_access_token, oauth2_schema +from linguaphoto.utils.auth import create_access_token, decode_access_token, oauth2_schema router = APIRouter() diff --git a/linguaphoto/config.py b/linguaphoto/config.py index 4fc513b..dfe00b1 100644 --- a/linguaphoto/config.py +++ b/linguaphoto/config.py @@ -24,7 +24,8 @@ import aioboto3 import aioboto3.session from botocore.exceptions import NoCredentialsError -from settings import settings + +from linguaphoto.settings import settings async def get_dynamodb_resource() -> Any: # noqa: ANN401 diff --git a/linguaphoto/crud/base.py b/linguaphoto/crud/base.py index 3906c8a..d45cce7 100644 --- a/linguaphoto/crud/base.py +++ b/linguaphoto/crud/base.py @@ -7,12 +7,13 @@ import aioboto3 from boto3.dynamodb.conditions import ComparisonCondition, Key from botocore.exceptions import ClientError -from errors import InternalError, ItemNotFoundError -from models import BaseModel, LinguaBaseModel -from settings import settings from types_aiobotocore_dynamodb.service_resource import DynamoDBServiceResource from types_aiobotocore_s3.service_resource import S3ServiceResource +from linguaphoto.errors import InternalError, ItemNotFoundError +from linguaphoto.models import BaseModel, LinguaBaseModel +from linguaphoto.settings import settings + T = TypeVar("T", bound=BaseModel) TABLE_NAME = settings.dynamodb_table_name diff --git a/linguaphoto/crud/collection.py b/linguaphoto/crud/collection.py index 177b2b1..631287a 100644 --- a/linguaphoto/crud/collection.py +++ b/linguaphoto/crud/collection.py @@ -2,8 +2,8 @@ from typing import List -from crud.base import BaseCrud -from models import Collection +from linguaphoto.crud.base import BaseCrud +from linguaphoto.models import Collection class CollectionCrud(BaseCrud): diff --git a/linguaphoto/crud/image.py b/linguaphoto/crud/image.py index 8dfa9c7..61d7837 100644 --- a/linguaphoto/crud/image.py +++ b/linguaphoto/crud/image.py @@ -6,16 +6,17 @@ from typing import List import requests -from ai.transcribe import transcribe_image -from ai.tts import synthesize_text from boto3.dynamodb.conditions import Key -from crud.base import BaseCrud -from errors import ItemNotFoundError from fastapi import HTTPException, UploadFile -from models import Collection, Image from openai import AsyncOpenAI -from settings import settings -from utils.cloudfront_url_signer import CloudFrontUrlSigner + +from linguaphoto.ai.transcribe import transcribe_image +from linguaphoto.ai.tts import synthesize_text +from linguaphoto.crud.base import BaseCrud +from linguaphoto.errors import ItemNotFoundError +from linguaphoto.models import Collection, Image +from linguaphoto.settings import settings +from linguaphoto.utils.cloudfront_url_signer import CloudFrontUrlSigner key_pair_id = settings.key_pair_id media_hosting_server = settings.media_hosting_server diff --git a/linguaphoto/crud/user.py b/linguaphoto/crud/user.py index 1e424c3..b7edefb 100644 --- a/linguaphoto/crud/user.py +++ b/linguaphoto/crud/user.py @@ -2,9 +2,9 @@ from typing import List -from crud.base import BaseCrud -from models import User -from schemas.user import UserSigninFragment, UserSignupFragment +from linguaphoto.crud.base import BaseCrud +from linguaphoto.models import User +from linguaphoto.schemas.user import UserSigninFragment, UserSignupFragment class UserCrud(BaseCrud): diff --git a/linguaphoto/main.py b/linguaphoto/main.py index b4c5aab..4c4f21f 100644 --- a/linguaphoto/main.py +++ b/linguaphoto/main.py @@ -1,10 +1,11 @@ """Defines the main entrypoint for the FastAPI app.""" import uvicorn -from api.api import router from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware -from settings import settings + +from linguaphoto.api.api import router +from linguaphoto.settings import settings app = FastAPI() diff --git a/linguaphoto/models.py b/linguaphoto/models.py index a5febe4..4905f06 100644 --- a/linguaphoto/models.py +++ b/linguaphoto/models.py @@ -5,7 +5,8 @@ from bcrypt import checkpw, gensalt, hashpw from pydantic import BaseModel -from schemas.user import UserSignupFragment + +from linguaphoto.schemas.user import UserSignupFragment class LinguaBaseModel(BaseModel): diff --git a/linguaphoto/utils/auth.py b/linguaphoto/utils/auth.py index 7082d9d..97fc31a 100644 --- a/linguaphoto/utils/auth.py +++ b/linguaphoto/utils/auth.py @@ -15,10 +15,11 @@ from typing import Union import jwt -from crud.user import UserCrud from fastapi import Depends, HTTPException from fastapi.security import OAuth2PasswordBearer +from linguaphoto.crud.user import UserCrud + SECRET_KEY = "your_secret_key" ALGORITHM = "HS256" ACCESS_TOKEN_EXPIRE_MINUTES = 30