aflahafiM commited on
Commit
475ad31
·
verified ·
1 Parent(s): 2eac101

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -29
app.py CHANGED
@@ -3,8 +3,6 @@ import asyncio
3
  import tempfile
4
  import logging
5
  import edge_tts
6
- import google.generativeai as genai
7
- from typing import Optional, Tuple
8
  import os
9
  import nest_asyncio
10
 
@@ -15,10 +13,6 @@ nest_asyncio.apply()
15
  logging.basicConfig(level=logging.INFO)
16
  logger = logging.getLogger(__name__)
17
 
18
- # Initialize Gemini - Replace with your actual API key or use environment variable
19
- GEMINI_API_KEY = os.getenv("GEMINI_API_KEY", "AIzaSyCnpKy4zRvs2xx4Lm11SJ7gEbDZJR0vFrc")
20
- genai.configure(api_key=GEMINI_API_KEY)
21
-
22
  # Voice Configuration (Updated for edge-tts 6.x)
23
  VOICES = {
24
  "English": {
@@ -36,20 +30,8 @@ VOICES = {
36
  }
37
  }
38
 
39
- class ContentGenerator:
40
- def __init__(self):
41
- self.model = genai.GenerativeModel('gemini-pro')
42
-
43
- def generate(self, prompt: str) -> str:
44
- try:
45
- response = self.model.generate_content(prompt)
46
- return response.text
47
- except Exception as e:
48
- logger.error(f"Gemini error: {str(e)}")
49
- return f"⚠️ Content generation failed. Error: {str(e)}"
50
-
51
  async def text_to_speech(text: str, language: str, voice_type: str,
52
- rate: int, pitch: int) -> Tuple[Optional[str], Optional[str]]:
53
  try:
54
  if not text.strip():
55
  return None, "No text provided"
@@ -79,15 +61,20 @@ async def process_request(content_type: str, language: str, voice_type: str,
79
  length: int, theme: str, custom: str,
80
  rate: int, pitch: int):
81
  try:
82
- # Generate prompt
83
- prompt = f"""Generate {length} words of {content_type} content in {language}.
84
- Theme: {theme}
85
- Additional instructions: {custom if custom else 'None'}
86
- Format the text for optimal text-to-speech conversion."""
87
 
88
- # Generate content
89
- generator = ContentGenerator()
90
- text_content = generator.generate(prompt)
 
 
 
 
 
 
 
 
91
 
92
  # Convert to speech
93
  audio_path, error = await text_to_speech(
@@ -103,7 +90,7 @@ Format the text for optimal text-to-speech conversion."""
103
  def create_interface():
104
  with gr.Blocks(title="AI VoiceCraft", theme=gr.themes.Soft()) as app:
105
  gr.Markdown("""# 🎙️ AI VoiceCraft Studio
106
- *Generate content with Gemini and convert to natural speech*""")
107
 
108
  with gr.Row():
109
  with gr.Column():
@@ -147,4 +134,4 @@ def create_interface():
147
 
148
  if __name__ == "__main__":
149
  app = create_interface()
150
- app.queue(concurrency_count=3).launch()
 
3
  import tempfile
4
  import logging
5
  import edge_tts
 
 
6
  import os
7
  import nest_asyncio
8
 
 
13
  logging.basicConfig(level=logging.INFO)
14
  logger = logging.getLogger(__name__)
15
 
 
 
 
 
16
  # Voice Configuration (Updated for edge-tts 6.x)
17
  VOICES = {
18
  "English": {
 
30
  }
31
  }
32
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  async def text_to_speech(text: str, language: str, voice_type: str,
34
+ rate: int, pitch: int) -> tuple:
35
  try:
36
  if not text.strip():
37
  return None, "No text provided"
 
61
  length: int, theme: str, custom: str,
62
  rate: int, pitch: int):
63
  try:
64
+ # Generate sample content (replace with your actual content generation)
65
+ text_content = f"""**Generated {content_type} Content**
 
 
 
66
 
67
+ Language: {language}
68
+ Length: ~{length} words
69
+ Theme: {theme}
70
+
71
+ This is a sample generated content. In a real implementation, this would be:
72
+ - Properly formatted for TTS
73
+ - Tailored to your specifications
74
+ - Generated by an AI model
75
+
76
+ Custom instructions: {custom if custom else 'None'}
77
+ """
78
 
79
  # Convert to speech
80
  audio_path, error = await text_to_speech(
 
90
  def create_interface():
91
  with gr.Blocks(title="AI VoiceCraft", theme=gr.themes.Soft()) as app:
92
  gr.Markdown("""# 🎙️ AI VoiceCraft Studio
93
+ *Generate content and convert to natural speech*""")
94
 
95
  with gr.Row():
96
  with gr.Column():
 
134
 
135
  if __name__ == "__main__":
136
  app = create_interface()
137
+ app.queue().launch()