Update app.py
Browse files
app.py
CHANGED
|
@@ -74,53 +74,109 @@
|
|
| 74 |
# iface = gr.Interface(fn=function1, inputs="text", outputs=[gr.Audio(label="Audio",type="numpy")])
|
| 75 |
# iface.launch()
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
import gradio as gr
|
| 78 |
import requests
|
| 79 |
-
import urllib.request
|
| 80 |
-
from pydub import AudioSegment
|
| 81 |
-
import numpy as np
|
| 82 |
import os
|
| 83 |
-
import sys
|
| 84 |
-
import wave
|
| 85 |
-
import io
|
| 86 |
-
import base64
|
| 87 |
-
import azure.cognitiveservices.speech as speechsdk
|
| 88 |
-
|
| 89 |
-
speech_key = os.environ.get("test3")
|
| 90 |
-
service_region = os.environ.get("test4")
|
| 91 |
-
|
| 92 |
-
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
|
| 93 |
-
# Note: the voice setting will not overwrite the voice element in input SSML.
|
| 94 |
-
speech_config.speech_synthesis_voice_name = os.environ.get("test5")
|
| 95 |
|
| 96 |
-
def
|
| 97 |
response = requests.post("https://tommy24-testing3.hf.space/run/predict", json={
|
| 98 |
"data": [
|
| 99 |
prompt,
|
| 100 |
]}).json()
|
| 101 |
message = response["data"][0]
|
| 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 |
iface.launch()
|
|
|
|
| 74 |
# iface = gr.Interface(fn=function1, inputs="text", outputs=[gr.Audio(label="Audio",type="numpy")])
|
| 75 |
# iface.launch()
|
| 76 |
|
| 77 |
+
# import gradio as gr
|
| 78 |
+
# import requests
|
| 79 |
+
# import urllib.request
|
| 80 |
+
# from pydub import AudioSegment
|
| 81 |
+
# import numpy as np
|
| 82 |
+
# import os
|
| 83 |
+
# import sys
|
| 84 |
+
# import wave
|
| 85 |
+
# import io
|
| 86 |
+
# import base64
|
| 87 |
+
# import azure.cognitiveservices.speech as speechsdk
|
| 88 |
+
|
| 89 |
+
# speech_key = os.environ.get("test3")
|
| 90 |
+
# service_region = os.environ.get("test4")
|
| 91 |
+
|
| 92 |
+
# speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
|
| 93 |
+
# # Note: the voice setting will not overwrite the voice element in input SSML.
|
| 94 |
+
# speech_config.speech_synthesis_voice_name = os.environ.get("test5")
|
| 95 |
+
|
| 96 |
+
# def function1(prompt):
|
| 97 |
+
# response = requests.post("https://tommy24-testing3.hf.space/run/predict", json={
|
| 98 |
+
# "data": [
|
| 99 |
+
# prompt,
|
| 100 |
+
# ]}).json()
|
| 101 |
+
# message = response["data"][0]
|
| 102 |
+
# speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
|
| 103 |
+
# result = speech_synthesizer.speak_text_async(message).get()
|
| 104 |
+
# if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
|
| 105 |
+
# audio_stream = io.BytesIO(result.audio_data)
|
| 106 |
+
|
| 107 |
+
# # Create a wave file object and write the audio data to it
|
| 108 |
+
# with wave.open("audio.wav", 'wb') as wave_file:
|
| 109 |
+
# wave_file.setnchannels(1)
|
| 110 |
+
# wave_file.setsampwidth(2)
|
| 111 |
+
# wave_file.setframerate(16000)
|
| 112 |
+
# wave_file.writeframesraw(audio_stream.getvalue())
|
| 113 |
+
|
| 114 |
+
# # Use ffmpeg to convert the wave file to an mp3 file
|
| 115 |
+
# filename = "output.mp3"
|
| 116 |
+
|
| 117 |
+
# if os.path.exists(filename):
|
| 118 |
+
# os.remove(filename)
|
| 119 |
+
# else:
|
| 120 |
+
# pass
|
| 121 |
+
# command = f"ffmpeg -i audio.wav -y -codec:a libmp3lame -qscale:a 2 {filename}"
|
| 122 |
+
# os.system(command)
|
| 123 |
+
# return "output.mp3"
|
| 124 |
+
|
| 125 |
+
# iface = gr.Interface(fn=function1, inputs="text", outputs=[gr.Audio(label="Audio",type="numpy")])
|
| 126 |
+
# iface.launch()
|
| 127 |
+
|
| 128 |
import gradio as gr
|
| 129 |
import requests
|
|
|
|
|
|
|
|
|
|
| 130 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
+
def function2(prompt):
|
| 133 |
response = requests.post("https://tommy24-testing3.hf.space/run/predict", json={
|
| 134 |
"data": [
|
| 135 |
prompt,
|
| 136 |
]}).json()
|
| 137 |
message = response["data"][0]
|
| 138 |
+
|
| 139 |
+
url = "https://api.dynapictures.com/designs/7c4aba1d73"
|
| 140 |
+
headers = {
|
| 141 |
+
"Authorization": "Bearer d11937f0c9b7f55db1916f11abbe05c5917798f562506f11",
|
| 142 |
+
"Content-Type": "application/json"
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
payload = {
|
| 146 |
+
"format": "jpeg",
|
| 147 |
+
"metadata": "some text",
|
| 148 |
+
"params": [
|
| 149 |
+
{
|
| 150 |
+
"name": "bubble",
|
| 151 |
+
"imageUrl": "https://dynapictures.com/b/rest/public/media/0ceb636a01/images/568b337221.png"
|
| 152 |
+
},
|
| 153 |
+
{
|
| 154 |
+
"name": "quotes",
|
| 155 |
+
"imageUrl": "https://dynapictures.com/b/rest/public/media/0ceb636a01/images/779f8b9041.png"
|
| 156 |
+
},
|
| 157 |
+
{
|
| 158 |
+
"name": "text",
|
| 159 |
+
"text": message
|
| 160 |
+
},
|
| 161 |
+
{
|
| 162 |
+
"name": "avatar",
|
| 163 |
+
"imageUrl": "https://dynapictures.com/b/rest/public/media/0ceb636a01/images/2f7ddd7b55.jpg"
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"name": "name",
|
| 167 |
+
"text": "JohnAI"
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"name": "title",
|
| 171 |
+
"text": "Automated"
|
| 172 |
+
}
|
| 173 |
+
]
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
response = requests.post(url, headers=headers, data=json.dumps(payload))
|
| 177 |
+
response = response.json()
|
| 178 |
+
response = response["imageUrl"]
|
| 179 |
+
return response
|
| 180 |
+
|
| 181 |
+
iface = gr.Interface(fn=function1, inputs="text", outputs="text")
|
| 182 |
iface.launch()
|