Groq-GPT / app.py
LichtLiu's picture
update
f423ab3
# app.py (main.py)
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()}")
# 初始化 Groq 客戶端
self.client = Groq(api_key=GROQ_API_KEY)
# 初始化所有服務
self.initialize_services()
# 初始化 Gradio 介面
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 模型和語音辨識服務
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,
)
# 初始化 LLaVA 模型
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):
"""執行"""
# 啟動 Gradio 介面
self.interface.launch(debug=True)
def main():
app = App()
app.run()
if __name__ == "__main__":
main()