Spaces:
Runtime error
Runtime error
File size: 2,499 Bytes
c688a3b 6d7dbcd 180d8aa 3c1ac4e c688a3b 3c1ac4e c688a3b 3c1ac4e 6d7dbcd 5f3392e 3c1ac4e 180d8aa 3c1ac4e 180d8aa f7709d8 3708b8e 180d8aa 3c1ac4e 180d8aa 3c1ac4e c52d065 9fdfed4 c52d065 9fdfed4 c688a3b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
import openai
import os
import random
from langchain.prompts import PromptTemplate
from modules.gpt_modules import gpt_call
# from dotenv import dotenv_values
# config = dotenv_values(".env")
# if config:
# openai.organization = config.get('OPENAI_ORGANIZATION')
# openai.api_key = config.get('OPENAI_API_KEY')
# else:
# openai.organization = st.secrets['OPENAI_ORGANIZATION'] #config.get('OPENAI_ORGANIZATION')
# openai.api_key = st.secrets['OPENAI_API_KEY'] #config.get('OPENAI_API_KEY')
def debate_in_sound(api_key, audio):
os.rename(audio, audio + '.wav')
file = open(audio + '.wav', "rb")
openai.api_key = api_key
# user_words
user_prompt = openai.Audio.transcribe("whisper-1", file).text
print("**************************************")
print("user_audio transcription", user_prompt)
print("**************************************")
# Testing Prompt
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."
debate_role = [
"pro side",
"con side",
]
user_debate_role = random.choice(debate_role)
bot_debate_role = "".join([role for role in debate_role if role != user_debate_role])
debate_preset = "\n".join([
"Debate Rules: ",
"1) This debate will be divided into pro and con",
"2) You must counter user's arguments",
"3) Answer logically with an introduction, body, and conclusion.\n", #add this one.
"User debate role: " + user_debate_role,
"Bot debate roles: " + bot_debate_role + "\n",
"Debate subject: " + debate_subject
])
prompt_template = PromptTemplate(
input_variables=["prompt"],
template="\n".join([
debate_preset, #persona
"User: {prompt}",
"Bot: "
])
)
bot_prompt = prompt_template.format(
prompt=user_prompt
)
response = gpt_call(api_key, bot_prompt)
return response
def whisper_transcribe(api_key, audio_file):
openai.api_key = api_key
audio_file= open("audio/audio.wav", "rb")
result = openai.Audio.transcribe("whisper-1", audio_file).text
audio_file.close()
return result
|