File size: 6,981 Bytes
ce74a88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b837136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ad0a66
 
6db6ca1
f92ea75
9ad0a66
852bf6b
f92ea75
 
 
504ee76
 
 
 
 
 
 
 
 
 
f92ea75
 
 
 
 
 
 
 
 
 
 
83ea675
9f985e0
6db6ca1
 
 
f92ea75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ad0a66
f92ea75
 
 
 
 
 
9ad0a66
f92ea75
 
9ad0a66
f92ea75
 
 
 
 
 
 
 
 
 
9ad0a66
0b7f87e
 
9ad0a66
0b7f87e
 
9ad0a66
0b7f87e
 
 
 
 
 
9ad0a66
 
 
 
 
 
0b7f87e
9ad0a66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e695abb
9ad0a66
 
 
 
0b7f87e
9ad0a66
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# 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.environ.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()


# import gradio as gr
# import requests
# import urllib.request
# from pydub import AudioSegment
# import numpy as np
# import os

# def function1(prompt):
#     response = requests.post("https://tommy24-testing3.hf.space/run/predict", json={
#       "data": [
#         prompt,
#     ]}).json()
#     data = response["data"][0]
#     response = requests.post("https://matthijs-speecht5-tts-demo.hf.space/run/predict", json={
#         "data": [
#             data,
#             "KSP (male)",
#         ]
#     }).json()
#     data = response["data"][0]["name"]
#     data = "https://matthijs-speecht5-tts-demo.hf.space/file="+data
#     file_name, headers = urllib.request.urlretrieve(data, "speech.mp3")
#     # code = random.randint(1,1000)
#     # generated_file = f"output{code}"
#     filename = "output.mp3"
    
#     if os.path.exists(filename):
#         os.remove(filename)
#     else:
#         pass
#     command = f"ffmpeg -i {file_name} -vn -ar 44100 -ac 2 -b:a 192k output.mp3"
#     os.system(command)
#     return "output.mp3"

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

import gradio as gr
import requests
import base64
import time
import os
import re

def function(prompt):
    url = os.environ.get("test7")
    referrer = os.environ.get("test13")
    headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299",
    "Accept": "application/json",
    "Accept-Language": "en-US,en;q=0.5",
    "Referer": referrer,
    "Connection": "keep-alive",
    "TE": "Trailers",
    "Flag-Real-Time-Data": "true"
    }
    data = {
        "input": prompt
    }
    response = requests.post(url, headers=headers, json=data)
    response = response.json()
    output = response["output"]
    trigger1 = os.environ.get("test9")
    trigger2 = os.environ.get("test10")
    set1 = os.environ.get("test11")
    set2 = os.environ.get("test12")
    if trigger1 in output and trigger2 in output:
        output = re.sub(trigger2, set1, output)
        output = re.sub(trigger1, set2, output)
    result = base64.b64encode(output.encode('utf-8'))
    result2 = result.decode('utf-8')
    return output

iface = gr.Interface(fn=function, inputs="text", outputs="text")
iface.launch()

# ********************************************************************************************
# import gradio as gr
# import requests
# import urllib.request
# from pydub import AudioSegment
# import numpy as np
# import os
# import sys
# import wave
# import io
# import base64
# import azure.cognitiveservices.speech as speechsdk

# speech_key = os.environ.get("test3")
# service_region = os.environ.get("test4")

# speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
# # Note: the voice setting will not overwrite the voice element in input SSML.
# speech_config.speech_synthesis_voice_name = os.environ.get("test5")

# def function1(prompt):
#     response = requests.post("https://tommy24-testing3.hf.space/run/predict", json={
#       "data": [
#         prompt,
#     ]}).json()
#     message = response["data"][0]
#     speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
#     result = speech_synthesizer.speak_text_async(message).get()
#     if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
#         audio_stream = io.BytesIO(result.audio_data)
    
#         # Create a wave file object and write the audio data to it
#         with wave.open("audio.wav", 'wb') as wave_file:
#             wave_file.setnchannels(1)
#             wave_file.setsampwidth(2)
#             wave_file.setframerate(16000)
#             wave_file.writeframesraw(audio_stream.getvalue())
        
#         # Use ffmpeg to convert the wave file to an mp3 file
#         filename = "output.mp3"
        
#         if os.path.exists(filename):
#             os.remove(filename)
#         else:
#             pass
#         command = f"ffmpeg -i audio.wav -y -codec:a libmp3lame -qscale:a 2 {filename}"
#         os.system(command)
#         return "output.mp3"

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

# import gradio as gr
# import requests
# import json
# import os

# def function2(prompt):
#     response = requests.post("https://tommy24-testing3.hf.space/run/predict", json={
#       "data": [
#         prompt,
#     ]}).json()
#     message = response["data"][0]

#     url = "https://api.dynapictures.com/designs/7c4aba1d73"
#     test6 = os.environ.get("test6")
#     headers = {
#         "Authorization": f"Bearer {test6}",
#         "Content-Type": "application/json"
#     }

#     payload = {
#       "format": "jpeg",
#       "metadata": "some text",
#       "params": [
#         {
#           "name": "bubble",
#           "imageUrl": "https://dynapictures.com/b/rest/public/media/0ceb636a01/images/568b337221.png"
#         },
#         {
#           "name": "quotes",
#           "imageUrl": "https://dynapictures.com/b/rest/public/media/0ceb636a01/images/779f8b9041.png"
#         },
#         {
#           "name": "text",
#           "text": message
#         },
#         {
#           "name": "avatar",
#           "imageUrl": "https://dynapictures.com/b/rest/public/media/0ceb636a01/images/2f7ddd7b55.jpg"
#         },
#         {
#           "name": "name",
#           "text": "JohnAI"
#         },
#         {
#           "name": "title",
#           "text": "Automated"
#         }
#       ]
#     }

#     response = requests.post(url, headers=headers, data=json.dumps(payload))
#     response = response.json()
#     response = response["imageUrl"]
#     return response

# iface = gr.Interface(fn=function2, inputs="text", outputs="text")
# iface.launch()