|
|
|
import torch |
|
from groq import Groq |
|
import os |
|
from datetime import datetime |
|
import numpy as np |
|
|
|
|
|
from src.services.chat_service import ChatService |
|
from src.services.file_service import FileService |
|
from src.services.speech_recognition_service import SpeechRecognitionService |
|
from src.services.speech_service import SpeechService |
|
from src.services.translation_service import TranslationService |
|
|
|
from src.models.groq_tool_model import GroqToolModel |
|
from src.models.whisper_model import WhisperModel |
|
from src.models.speech_model import SpeechModel |
|
from src.models.llava_model import LLaVAModel |
|
from src.models.translator_model import TranslatorModel |
|
|
|
|
|
from src.routes.gradio_routes import GradioInterface |
|
|
|
|
|
from config.config import ( |
|
GROQ_API_KEY, |
|
AUDIO_MODEL |
|
) |
|
|
|
class App: |
|
def __init__(self): |
|
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
|
print(f"Is CUDA available: {torch.cuda.is_available()}") |
|
|
|
|
|
self.client = Groq(api_key=GROQ_API_KEY) |
|
|
|
|
|
self.initialize_services() |
|
|
|
|
|
self.interface = GradioInterface( |
|
chat_service=self.chat_service, |
|
file_service=self.file_service |
|
) |
|
|
|
def initialize_services(self): |
|
"""初始化所有服務""" |
|
|
|
|
|
self.groq_tool_model = GroqToolModel() |
|
|
|
|
|
self.file_service = FileService() |
|
|
|
|
|
whisper_model = WhisperModel(self.client, AUDIO_MODEL) |
|
self.speech_recognition_service = SpeechRecognitionService(whisper_model) |
|
|
|
|
|
translator_model = TranslatorModel() |
|
self.translation_service = TranslationService(translator_model) |
|
|
|
|
|
speech_model = SpeechModel(device=self.device) |
|
self.speech_service = SpeechService( |
|
groq_client=self.client, |
|
speech_model=speech_model, |
|
) |
|
|
|
|
|
self.llava_model = LLaVAModel(device=self.device) |
|
|
|
|
|
self.chat_service = ChatService( |
|
client=self.client, |
|
model=self.groq_tool_model, |
|
speech_recognition_service=self.speech_recognition_service, |
|
translation_service=self.translation_service, |
|
speech_service=self.speech_service, |
|
llava_model=self.llava_model, |
|
file_service=self.file_service |
|
) |
|
|
|
def run(self): |
|
"""執行""" |
|
|
|
self.interface.launch(debug=True) |
|
|
|
def main(): |
|
app = App() |
|
app.run() |
|
|
|
if __name__ == "__main__": |
|
main() |