Spaces:
Sleeping
Sleeping
Ajit Panday commited on
Commit ·
6d5c3a1
1
Parent(s): dbb09da
Add application code and structure
Browse files- .gitignore +34 -0
- app/__init__.py +2 -0
- app/auth.py +1 -0
- app/models.py +43 -0
- main.py +76 -0
- requirements.txt +5 -2
.gitignore
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
venv/
|
| 8 |
+
ENV/
|
| 9 |
+
|
| 10 |
+
# Environment variables
|
| 11 |
+
.env
|
| 12 |
+
|
| 13 |
+
# IDE
|
| 14 |
+
.idea/
|
| 15 |
+
.vscode/
|
| 16 |
+
*.swp
|
| 17 |
+
*.swo
|
| 18 |
+
|
| 19 |
+
# Logs
|
| 20 |
+
*.log
|
| 21 |
+
|
| 22 |
+
# Database
|
| 23 |
+
*.db
|
| 24 |
+
*.sqlite3
|
| 25 |
+
|
| 26 |
+
# Audio files
|
| 27 |
+
*.wav
|
| 28 |
+
*.mp3
|
| 29 |
+
*.ogg
|
| 30 |
+
|
| 31 |
+
# Distribution / packaging
|
| 32 |
+
dist/
|
| 33 |
+
build/
|
| 34 |
+
*.egg-info/
|
app/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import models
|
| 2 |
+
from . import auth
|
app/auth.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
app/models.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sqlalchemy import Column, Integer, String, DateTime, create_engine
|
| 2 |
+
from sqlalchemy.ext.declarative import declarative_base
|
| 3 |
+
from sqlalchemy.orm import sessionmaker
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
import os
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
|
| 8 |
+
# Load environment variables
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
# Get database URL from environment variables
|
| 12 |
+
DATABASE_URL = os.getenv("DATABASE_URL")
|
| 13 |
+
|
| 14 |
+
# Create SQLAlchemy engine
|
| 15 |
+
engine = create_engine(DATABASE_URL)
|
| 16 |
+
|
| 17 |
+
# Create declarative base
|
| 18 |
+
Base = declarative_base()
|
| 19 |
+
|
| 20 |
+
class CallRecord(Base):
|
| 21 |
+
__tablename__ = "call_records"
|
| 22 |
+
|
| 23 |
+
id = Column(String(36), primary_key=True)
|
| 24 |
+
file_path = Column(String(255))
|
| 25 |
+
transcription = Column(String(10000))
|
| 26 |
+
sentiment = Column(String(20))
|
| 27 |
+
keywords = Column(String(1000))
|
| 28 |
+
created_at = Column(DateTime, default=datetime.utcnow)
|
| 29 |
+
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
| 30 |
+
|
| 31 |
+
# Create all tables
|
| 32 |
+
Base.metadata.create_all(engine)
|
| 33 |
+
|
| 34 |
+
# Create session factory
|
| 35 |
+
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
| 36 |
+
|
| 37 |
+
# Dependency to get database session
|
| 38 |
+
def get_db():
|
| 39 |
+
db = SessionLocal()
|
| 40 |
+
try:
|
| 41 |
+
yield db
|
| 42 |
+
finally:
|
| 43 |
+
db.close()
|
main.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, File, UploadFile, HTTPException, Depends
|
| 2 |
+
from fastapi.security import OAuth2PasswordBearer
|
| 3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
import os
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
from typing import List
|
| 8 |
+
import uuid
|
| 9 |
+
|
| 10 |
+
# Load environment variables
|
| 11 |
+
load_dotenv()
|
| 12 |
+
|
| 13 |
+
# Initialize FastAPI app
|
| 14 |
+
app = FastAPI(
|
| 15 |
+
title="vBot - Voice Call Analysis API",
|
| 16 |
+
description="API for processing and analyzing voice call recordings",
|
| 17 |
+
version="1.0.0"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# Add CORS middleware
|
| 21 |
+
app.add_middleware(
|
| 22 |
+
CORSMiddleware,
|
| 23 |
+
allow_origins=["*"],
|
| 24 |
+
allow_credentials=True,
|
| 25 |
+
allow_methods=["*"],
|
| 26 |
+
allow_headers=["*"],
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# OAuth2 scheme for token authentication
|
| 30 |
+
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
| 31 |
+
|
| 32 |
+
# Dependency for authentication
|
| 33 |
+
async def get_current_user(token: str = Depends(oauth2_scheme)):
|
| 34 |
+
# TODO: Implement proper JWT token validation
|
| 35 |
+
if not token:
|
| 36 |
+
raise HTTPException(
|
| 37 |
+
status_code=401,
|
| 38 |
+
detail="Could not validate credentials",
|
| 39 |
+
headers={"WWW-Authenticate": "Bearer"},
|
| 40 |
+
)
|
| 41 |
+
return token
|
| 42 |
+
|
| 43 |
+
@app.post("/api/v1/process-call")
|
| 44 |
+
async def process_call(
|
| 45 |
+
file: UploadFile = File(...),
|
| 46 |
+
current_user: str = Depends(get_current_user)
|
| 47 |
+
):
|
| 48 |
+
"""
|
| 49 |
+
Process a voice call recording file.
|
| 50 |
+
"""
|
| 51 |
+
try:
|
| 52 |
+
# Generate unique ID for this processing request
|
| 53 |
+
process_id = str(uuid.uuid4())
|
| 54 |
+
|
| 55 |
+
# TODO: Implement actual file processing logic
|
| 56 |
+
# 1. Save the file temporarily
|
| 57 |
+
# 2. Process audio using ML models
|
| 58 |
+
# 3. Clean up temporary files
|
| 59 |
+
|
| 60 |
+
# Mock response for now
|
| 61 |
+
return {
|
| 62 |
+
"id": process_id,
|
| 63 |
+
"text": "Sample transcribed text",
|
| 64 |
+
"sentiment": "neutral",
|
| 65 |
+
"keywords": ["sample", "keywords"],
|
| 66 |
+
"timestamp": datetime.utcnow().isoformat() + "Z"
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
except Exception as e:
|
| 70 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
import uvicorn
|
| 74 |
+
host = os.getenv("HOST", "0.0.0.0")
|
| 75 |
+
port = int(os.getenv("PORT", 7860))
|
| 76 |
+
uvicorn.run("main:app", host=host, port=port, reload=True)
|
requirements.txt
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
fastapi==0.109.2
|
| 2 |
uvicorn==0.27.1
|
| 3 |
python-multipart==0.0.9
|
| 4 |
-
python-jose==3.3.0
|
| 5 |
sqlalchemy==2.0.27
|
| 6 |
pymysql==1.1.0
|
| 7 |
-
cryptography==42.0.2
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
fastapi==0.109.2
|
| 2 |
uvicorn==0.27.1
|
| 3 |
python-multipart==0.0.9
|
| 4 |
+
python-jose[cryptography]==3.3.0
|
| 5 |
sqlalchemy==2.0.27
|
| 6 |
pymysql==1.1.0
|
| 7 |
+
cryptography==42.0.2
|
| 8 |
+
python-dotenv==1.0.0
|
| 9 |
+
passlib[bcrypt]==1.7.4
|
| 10 |
+
PyJWT==2.8.0
|