init
Browse files- .gitignore +3 -0
- app.py +81 -0
- flagged/log.csv +2 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
.env
|
2 |
+
*.mp3
|
3 |
+
__pycache__/
|
app.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from pathlib import Path
|
3 |
+
from openai import OpenAI
|
4 |
+
import os
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
|
7 |
+
# Load environment variables from .env file
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
# Initialize the OpenAI client
|
11 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
12 |
+
|
13 |
+
if not client.api_key:
|
14 |
+
raise ValueError("Please set the OPENAI_API_KEY in your .env file")
|
15 |
+
|
16 |
+
def generate_versions(text):
|
17 |
+
prompt = f"""Given the original text: "{text}"
|
18 |
+
Generate two rephrased versions:
|
19 |
+
1. A slightly more emotional version (ex. "μνν΄μ" -> "μνν΄μ!!")
|
20 |
+
2. An exaggerated, highly emotional version (ex. "μνν΄μ" -> "μ κΉλ§μ! μλΌ, μνν΄μ!!")
|
21 |
+
Output format:
|
22 |
+
Original: [original text]
|
23 |
+
Emotional: [emotional version]
|
24 |
+
Exaggerated: [exaggerated version]"""
|
25 |
+
|
26 |
+
stream = client.chat.completions.create(
|
27 |
+
model="gpt-4o-mini",
|
28 |
+
messages=[{"role": "user", "content": prompt}],
|
29 |
+
stream=True,
|
30 |
+
)
|
31 |
+
|
32 |
+
full_response = ""
|
33 |
+
for chunk in stream:
|
34 |
+
if chunk.choices[0].delta.content is not None:
|
35 |
+
full_response += chunk.choices[0].delta.content
|
36 |
+
|
37 |
+
versions = full_response.split('\n')
|
38 |
+
return [v.split(': ', 1)[1] for v in versions if ': ' in v]
|
39 |
+
|
40 |
+
def text_to_speech(text):
|
41 |
+
response = client.audio.speech.create(
|
42 |
+
model="tts-1",
|
43 |
+
voice="alloy",
|
44 |
+
input=text
|
45 |
+
)
|
46 |
+
return response.content
|
47 |
+
|
48 |
+
def process_and_generate(text):
|
49 |
+
versions = generate_versions(text)
|
50 |
+
audio_contents = [text_to_speech(v) for v in versions]
|
51 |
+
return versions + audio_contents + ["All versions generated successfully!"]
|
52 |
+
|
53 |
+
with gr.Blocks(title="Emotional TTS Comparison") as demo:
|
54 |
+
gr.Markdown("# Emotional TTS Comparison")
|
55 |
+
gr.Markdown("Enter text to generate three versions with varying emotional intensity.")
|
56 |
+
|
57 |
+
input_text = gr.Textbox(label="Original Text", lines=3)
|
58 |
+
generate_btn = gr.Button("Generate Versions and Speech")
|
59 |
+
|
60 |
+
with gr.Row():
|
61 |
+
text1 = gr.Textbox(label="Original Version")
|
62 |
+
text2 = gr.Textbox(label="Emotional Version")
|
63 |
+
text3 = gr.Textbox(label="Exaggerated Version")
|
64 |
+
|
65 |
+
with gr.Row():
|
66 |
+
audio1 = gr.Audio(label="Original Speech")
|
67 |
+
audio2 = gr.Audio(label="Emotional Speech")
|
68 |
+
audio3 = gr.Audio(label="Exaggerated Speech")
|
69 |
+
|
70 |
+
status = gr.Textbox(label="Status")
|
71 |
+
|
72 |
+
generate_btn.click(
|
73 |
+
process_and_generate,
|
74 |
+
inputs=[input_text],
|
75 |
+
outputs=[text1, text2, text3, audio1, audio2, audio3, status]
|
76 |
+
)
|
77 |
+
|
78 |
+
if __name__ == "__main__":
|
79 |
+
demo.launch()
|
80 |
+
else:
|
81 |
+
demo.launch(share=True)
|
flagged/log.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
Enter text to convert to speech,Status,flag,username,timestamp
|
2 |
+
,,,,2024-09-27 13:12:27.212281
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
openai
|