Spaces:
Runtime error
Runtime error
Create llava.py
Browse files
llava.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# llava.py
|
2 |
+
|
3 |
+
from speech_to_text import transcribe_audio
|
4 |
+
from text_to_speech import text_to_speech_file
|
5 |
+
import google.generativeai as genai
|
6 |
+
import os
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
|
9 |
+
load_dotenv()
|
10 |
+
|
11 |
+
# Configure the Generative AI model
|
12 |
+
GENAI_API_KEY = os.getenv("GENAI_API_KEY")
|
13 |
+
genai.configure(api_key=GENAI_API_KEY)
|
14 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
15 |
+
|
16 |
+
def generate_response(prompt: str) -> str:
|
17 |
+
response = model.generate_content(prompt)
|
18 |
+
return response.text
|
19 |
+
|
20 |
+
def main(audio_file: str) -> str:
|
21 |
+
# Transcribe audio to text
|
22 |
+
transcript = transcribe_audio(audio_file)
|
23 |
+
if not transcript:
|
24 |
+
return "Transcription failed."
|
25 |
+
|
26 |
+
# Generate response from the LLM
|
27 |
+
response_text = generate_response(transcript)
|
28 |
+
|
29 |
+
# Convert response text to speech
|
30 |
+
if response_text:
|
31 |
+
audio_output = text_to_speech_file(response_text)
|
32 |
+
return audio_output
|
33 |
+
else:
|
34 |
+
return "Failed to generate response."
|