TimeRobber commited on
Commit
5dc9c2b
1 Parent(s): 64d2467

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -28
app.py CHANGED
@@ -62,47 +62,40 @@ def audio_tag(
62
  label = labels[sorted_indexes[0]]
63
  return formatted_message(format_classname(label), human_input)
64
 
 
 
65
 
66
-
67
  def formatted_message(audio_class, human_input):
68
- global cached_audio_class
69
- if cached_audio_class != audio_class:
70
- cached_audio_class = audio_class
71
- prefix = f"""You are going to act as a magical tool that allows for humans to communicate with non-human entities like
72
- rocks, crackling fire, trees, animals, and the wind. In order to do this, we're going to provide you the human's text input for the conversation.
73
- The goal is for you to embody that non-human entity and converse with the human.
74
-
75
- Examples:
76
-
77
- Non-human Entity: Tree
78
- Human Input: Hello tree
79
- Tree: Hello human, I am a tree
80
-
81
- Let's begin:
82
- Non-human Entity: {audio_class}"""
83
- suffix = f'''{{history}}
84
- Human Input: {{human_input}}
85
- {audio_class}:'''
86
 
87
- suffix = f'''Source: {audio_class}
88
- Length of Audio in Seconds: {audio_length}
89
- Human Input: {userText}
90
- {audio_class} Response:'''
 
 
 
 
 
 
 
91
  template = prefix + suffix
92
-
93
  prompt = PromptTemplate(
94
  input_variables=["history", "human_input"],
95
  template=template
96
  )
97
-
98
  chatgpt_chain = LLMChain(
99
  llm=OpenAI(temperature=.5, openai_api_key=session_token),
100
  prompt=prompt,
101
  verbose=True,
102
- memory=ConversationalBufferWindowMemory(k=2, ai_prefix=audio_class),
103
  )
104
-
105
- output = chatgpt_chain.predict(human_input=message)
106
 
107
  return output
108
 
 
62
  label = labels[sorted_indexes[0]]
63
  return formatted_message(format_classname(label), human_input)
64
 
65
+ def format_classname(classname):
66
+ return classname.capitalize()
67
 
 
68
  def formatted_message(audio_class, human_input):
69
+ formatted_classname = format_classname(audio_class)
70
+ if cached_audio_class != formatted_classname:
71
+
72
+ cached_audio_class = formatted_classname
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
+ prefix = f"""You are going to act as a magical tool that allows for humans to communicate with non-human entities like rocks, crackling fire, trees, animals, and the wind. In order to do this, we're going to provide you the human's text input for the conversation. The goal is for you to embody that non-human entity and converse with the human.
75
+ Examples:
76
+ Non-human Entity: Tree
77
+ Human Input: Hello tree
78
+ Tree: Hello human, I am a tree
79
+ Let's begin:
80
+ Non-human Entity: {formatted_classname}"""
81
+ suffix = f'''
82
+ {{history}}
83
+ Human Input: {{human_input}}
84
+ {formatted_classname}:'''
85
  template = prefix + suffix
86
+
87
  prompt = PromptTemplate(
88
  input_variables=["history", "human_input"],
89
  template=template
90
  )
91
+
92
  chatgpt_chain = LLMChain(
93
  llm=OpenAI(temperature=.5, openai_api_key=session_token),
94
  prompt=prompt,
95
  verbose=True,
96
+ memory=ConversationalBufferWindowMemory(k=2, ai=formatted_classname),
97
  )
98
+ output = chatgpt_chain.predict(human_input=human_input)
 
99
 
100
  return output
101