File size: 1,018 Bytes
e695abb
303db20
9269376
e695abb
303db20
dd250a3
 
 
 
5e9a4dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3ee49d
8ea6338
c3ee49d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
import requests
import os

def function1(prompt):
    response = requests.post("https://tommy24-testing3.hf.space/run/predict", json={
      "data": [
        prompt,
    ]}).json()
    message = response["data"][0]
    url = 'https://api.elevenlabs.io/v1/text-to-speech/pNInz6obpgDQGcFmaJgB'

    headers = {
        'accept': 'audio/mpeg',
        'xi-api-key': os.enivron.get("test2"),
        'Content-Type': 'application/json'
    }

    data = {
        "text": message,
        "voice_settings": {
            "stability": 0,
            "similarity_boost": 0
        }
    }

    response = requests.post(url, headers=headers, json=data)
    if response.status_code == 200:
        file_path = 'test.mp3'
        if os.path.isfile(file_path):
            os.remove(file_path)
        with open(file_path, 'wb') as f:
            f.write(response.content)
    return "test.mp3"

iface = gr.Interface(fn=function1, inputs="text", outputs=[gr.Audio(label="Audio",type="numpy")])
iface.launch()