codingchild commited on
Commit
180d8aa
1 Parent(s): 96ab9a3

add gpt to whisper app

Browse files
Files changed (1) hide show
  1. whisper_app.py +47 -1
whisper_app.py CHANGED
@@ -3,6 +3,9 @@ import gradio as gr
3
  from dotenv import dotenv_values
4
  import openai
5
  import os
 
 
 
6
 
7
  """
8
  apt-get update
@@ -14,6 +17,49 @@ config = dotenv_values(".env")
14
  openai.organization = config.get('OPENAI_ORGANIZATION')
15
  openai.api_key = config.get('OPENAI_API_KEY')
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  def transcribe(audio):
19
  os.rename(audio, audio + '.wav')
@@ -25,7 +71,7 @@ def transcribe(audio):
25
 
26
  gr.Interface(
27
  title = 'Whisper Audio to Text with Speaker Recognition',
28
- fn=transcribe,
29
  inputs=[
30
  gr.inputs.Audio(source="microphone", type="filepath"),
31
  #gr.inputs.Number(default=2, label="Number of Speakers")
 
3
  from dotenv import dotenv_values
4
  import openai
5
  import os
6
+ from langchain.prompts import PromptTemplate
7
+ from modules.gpt_modules import gpt_call
8
+ import random
9
 
10
  """
11
  apt-get update
 
17
  openai.organization = config.get('OPENAI_ORGANIZATION')
18
  openai.api_key = config.get('OPENAI_API_KEY')
19
 
20
+ def debate(audio):
21
+ os.rename(audio, audio + '.wav')
22
+ file = open(audio + '.wav', "rb")
23
+
24
+ # user_words
25
+ user_prompt = openai.Audio.transcribe("whisper-1", file).text
26
+
27
+ # 일단 테스트를 위해 고정함
28
+ debate_subject = "In 2050, AI robots are able to replicate the appearance, conversation, and reaction to emotions of human beings. However, their intelligence still does not allow them to sense emotions and feelings such as pain, happiness, joy, and etc."
29
+
30
+ debate_role = [
31
+ "pro side",
32
+ "con side",
33
+ ]
34
+ user_debate_role = random.choice(debate_role)
35
+ bot_debate_role = "".join([role for role in debate_role if role != user_debate_role])
36
+
37
+ debate_preset = "\n".join([
38
+ "Debate Rules: ",
39
+ "1) This debate will be divided into pro and con",
40
+ "2) You must counter user's arguments",
41
+ "3) Answer logically with an introduction, body, and conclusion.\n", #add this one.
42
+ "User debate role: " + user_debate_role,
43
+ "Bot debate roles: " + bot_debate_role + "\n",
44
+ "Debate subject: " + debate_subject
45
+ ])
46
+
47
+ prompt_template = PromptTemplate(
48
+ input_variables=["prompt"],
49
+ template="\n".join([
50
+ debate_preset, #persona
51
+ "User: {prompt}",
52
+ "Bot: "
53
+ ])
54
+ )
55
+ bot_prompt = prompt_template.format(
56
+ prompt=user_prompt
57
+ )
58
+ response = gpt_call(bot_prompt)
59
+
60
+ return response
61
+
62
+
63
 
64
  def transcribe(audio):
65
  os.rename(audio, audio + '.wav')
 
71
 
72
  gr.Interface(
73
  title = 'Whisper Audio to Text with Speaker Recognition',
74
+ fn=debate,
75
  inputs=[
76
  gr.inputs.Audio(source="microphone", type="filepath"),
77
  #gr.inputs.Number(default=2, label="Number of Speakers")