avfranco commited on
Commit
a177e4d
1 Parent(s): 5195d28

OpenAI class migrated to latest version.

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -2,13 +2,15 @@ import os
2
  import spaces
3
  import torch
4
  import gradio as gr
5
- import openai
6
  from transformers import pipeline
7
 
8
  MODEL_NAME = "openai/whisper-large-v3"
9
  BATCH_SIZE = 8
10
  FILE_LIMIT_MB = 1000
11
 
 
 
12
  device = 0 if torch.cuda.is_available() else "cpu"
13
 
14
  pipe = pipeline(
@@ -24,8 +26,7 @@ def respond_to_question(transcript, question):
24
  # based on the transcript
25
  response = ""
26
  # Replace this with your OpenAI API key
27
- openai.api_key = os.environ["OPENAI_API_KEY"]
28
- response = openai.Completion.create(
29
  engine="gpt-4o-mini",
30
  prompt=f"Transcript: {transcript}\n\nUser: {question}\n\nAI:",
31
  temperature=0.3,
@@ -34,8 +35,9 @@ def respond_to_question(transcript, question):
34
  frequency_penalty=0,
35
  presence_penalty=0
36
  ).choices[0].text
37
- return response
38
 
 
 
39
  @spaces.GPU
40
  def audio_transcribe(inputs):
41
  if inputs is None:
 
2
  import spaces
3
  import torch
4
  import gradio as gr
5
+ from openai import OpenAI
6
  from transformers import pipeline
7
 
8
  MODEL_NAME = "openai/whisper-large-v3"
9
  BATCH_SIZE = 8
10
  FILE_LIMIT_MB = 1000
11
 
12
+ client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
13
+
14
  device = 0 if torch.cuda.is_available() else "cpu"
15
 
16
  pipe = pipeline(
 
26
  # based on the transcript
27
  response = ""
28
  # Replace this with your OpenAI API key
29
+ response = client.completions.create(
 
30
  engine="gpt-4o-mini",
31
  prompt=f"Transcript: {transcript}\n\nUser: {question}\n\nAI:",
32
  temperature=0.3,
 
35
  frequency_penalty=0,
36
  presence_penalty=0
37
  ).choices[0].text
 
38
 
39
+ return response
40
+
41
  @spaces.GPU
42
  def audio_transcribe(inputs):
43
  if inputs is None: