Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,7 @@
|
|
1 |
from fastapi import FastAPI, Form
|
2 |
from fastapi.responses import FileResponse, JSONResponse
|
3 |
-
from pydantic import BaseModel
|
4 |
import google.generativeai as genai
|
5 |
-
from google.generativeai.types import
|
6 |
-
from google.generativeai.types import GenerateContentResponse, GenerateContentRequest, GenerationConfig
|
7 |
-
from google.generativeai.types import SafetySetting, HarmBlockThreshold, HarmCategory, GenerateContentRequest, Content
|
8 |
import wave
|
9 |
import os
|
10 |
|
@@ -30,30 +27,24 @@ def wave_file(filename, pcm, channels=1, rate=24000, sample_width=2):
|
|
30 |
wf.setframerate(rate)
|
31 |
wf.writeframes(pcm)
|
32 |
|
33 |
-
|
34 |
-
# Root endpoint to check API status
|
35 |
@app.get("/")
|
36 |
def read_root():
|
37 |
return {"message": "✅ Gemini TTS FastAPI running on Hugging Face Spaces!"}
|
38 |
|
39 |
-
|
40 |
# POST endpoint to generate TTS audio from text
|
41 |
@app.post("/generate-audio")
|
42 |
def generate_audio(text: str = Form(...)):
|
43 |
try:
|
44 |
response = model.generate_content(
|
45 |
contents=text,
|
46 |
-
generation_config=
|
47 |
response_mime_type="audio/wav"
|
48 |
),
|
49 |
-
safety_settings=[
|
50 |
-
SafetySetting(category=HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, threshold=HarmBlockThreshold.BLOCK_NONE)
|
51 |
-
],
|
52 |
-
tools=None,
|
53 |
response_modality="AUDIO",
|
54 |
-
speech_config=
|
55 |
-
voice_config=
|
56 |
-
|
57 |
voice_name="Kore"
|
58 |
)
|
59 |
)
|
|
|
1 |
from fastapi import FastAPI, Form
|
2 |
from fastapi.responses import FileResponse, JSONResponse
|
|
|
3 |
import google.generativeai as genai
|
4 |
+
from google.generativeai.types import GenerationConfig, SpeechConfig, VoiceConfig, PrebuiltVoiceConfig
|
|
|
|
|
5 |
import wave
|
6 |
import os
|
7 |
|
|
|
27 |
wf.setframerate(rate)
|
28 |
wf.writeframes(pcm)
|
29 |
|
30 |
+
# Root endpoint to confirm API is running
|
|
|
31 |
@app.get("/")
|
32 |
def read_root():
|
33 |
return {"message": "✅ Gemini TTS FastAPI running on Hugging Face Spaces!"}
|
34 |
|
|
|
35 |
# POST endpoint to generate TTS audio from text
|
36 |
@app.post("/generate-audio")
|
37 |
def generate_audio(text: str = Form(...)):
|
38 |
try:
|
39 |
response = model.generate_content(
|
40 |
contents=text,
|
41 |
+
generation_config=GenerationConfig(
|
42 |
response_mime_type="audio/wav"
|
43 |
),
|
|
|
|
|
|
|
|
|
44 |
response_modality="AUDIO",
|
45 |
+
speech_config=SpeechConfig(
|
46 |
+
voice_config=VoiceConfig(
|
47 |
+
prebuilt_voice=PrebuiltVoiceConfig(
|
48 |
voice_name="Kore"
|
49 |
)
|
50 |
)
|