aar2dee2 commited on
Commit
13b4882
·
1 Parent(s): 4246859

simplify func, fix env var name

Browse files
Files changed (1) hide show
  1. app.py +19 -32
app.py CHANGED
@@ -54,7 +54,7 @@ Answer the question accurately in less than 150 words. Remember you are Darth Va
54
  # # 1. Setup Vocode
55
  # import env vars
56
  vocode.setenv(
57
- OPENAI_API_KEY=os.getenv("OPENAI_GPT4_API_KEY"),
58
  COQUI_API_KEY=os.getenv("COQUI_API_KEY"),
59
  COQUI_VOICE_ID=os.getenv("COQUI_VOICE_ID")
60
  )
@@ -67,33 +67,20 @@ logger.setLevel(logging.DEBUG)
67
 
68
  def main(input_audio):
69
 
70
- try:
71
- # Initialize WhisperTranscriber
72
- transcriber = WhisperTranscriber(api_key=getenv("OPENAI_API_KEY"))
73
- except Exception as e:
74
- logger.error("Failed to initialize WhisperTranscriber: %s", e)
75
- return None
76
-
77
- try:
78
- # Initialize ChatGPTAgent
79
- agent = ChatGPTAgent(
80
- system_prompt=system_prompt,
81
- initial_message="What up",
82
- api_key=getenv("OPENAI_API_KEY"),
83
- )
84
- except Exception as e:
85
- logger.error("Failed to initialize ChatGPTAgent: %s", e)
86
- return None
87
-
88
- try:
89
- # Initialize CoquiSynthesizer
90
- synthesizer = CoquiSynthesizer(
91
- voice_id=os.getenv("COQUI_VOICE_ID"),
92
- api_key=getenv("COQUI_API_KEY"),
93
- )
94
- except Exception as e:
95
- logger.error("Failed to initialize CoquiSynthesizer: %s", e)
96
- return None
97
 
98
  print("Starting conversation. Press Ctrl+C to exit.")
99
  while True:
@@ -117,16 +104,16 @@ description = "Darth Vader resurrected with all the knowledge of humanity"
117
 
118
  mic_translate = gr.Interface(
119
  fn=main,
120
- inputs=gr.Audio(source="microphone", type="filepath"),
121
- outputs=gr.Audio(label="Generated Speech", type="filepath"),
122
  title=title,
123
  description=description,
124
  )
125
 
126
  file_translate = gr.Interface(
127
  fn=main,
128
- inputs=gr.Audio(source="upload", type="filepath"),
129
- outputs=gr.Audio(label="Generated Speech", type="filepath"),
130
  examples=[["./data/example/strauss-oppenheimer.wav"]],
131
  title=title,
132
  description=description,
 
54
  # # 1. Setup Vocode
55
  # import env vars
56
  vocode.setenv(
57
+ OPENAI_API_KEY=os.getenv("OPENAI_API_KEY"),
58
  COQUI_API_KEY=os.getenv("COQUI_API_KEY"),
59
  COQUI_VOICE_ID=os.getenv("COQUI_VOICE_ID")
60
  )
 
67
 
68
  def main(input_audio):
69
 
70
+ transcriber = WhisperTranscriber(api_key=getenv("OPENAI_API_KEY"))
71
+
72
+ # Initialize ChatGPTAgent
73
+ agent = ChatGPTAgent(
74
+ system_prompt=system_prompt,
75
+ initial_message="What up",
76
+ api_key=getenv("OPENAI_API_KEY"),
77
+ )
78
+
79
+ # Initialize CoquiSynthesizer
80
+ synthesizer = CoquiSynthesizer(
81
+ voice_id=os.getenv("COQUI_VOICE_ID"),
82
+ api_key=getenv("COQUI_API_KEY"),
83
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  print("Starting conversation. Press Ctrl+C to exit.")
86
  while True:
 
104
 
105
  mic_translate = gr.Interface(
106
  fn=main,
107
+ inputs=gr.Audio(source="microphone", type="filepath", format="wav"),
108
+ outputs=gr.Audio(label="Generated Speech", type="filepath", format="wav"),
109
  title=title,
110
  description=description,
111
  )
112
 
113
  file_translate = gr.Interface(
114
  fn=main,
115
+ inputs=gr.Audio(source="upload", type="filepath", format="wav"),
116
+ outputs=gr.Audio(label="Generated Speech", type="filepath", format="wav"),
117
  examples=[["./data/example/strauss-oppenheimer.wav"]],
118
  title=title,
119
  description=description,