Files changed (1) hide show
  1. app.py +32 -30
app.py CHANGED
@@ -26,7 +26,8 @@ cached_audio_class = "c"
26
  template = None
27
  prompt = None
28
  chain = None
29
-
 
30
 
31
  def format_classname(classname):
32
  return classname.capitalize()
@@ -60,11 +61,11 @@ def audio_tag(
60
  # Print audio tagging top probabilities
61
 
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
  if cached_audio_class != audio_class:
69
  cached_audio_class = audio_class
70
  prefix = f"""You are going to act as a magical tool that allows for humans to communicate with non-human entities like
@@ -79,32 +80,31 @@ def formatted_message(audio_class, human_input):
79
 
80
  Let's begin:
81
  Non-human Entity: {audio_class}"""
82
- suffix = f'''{{history}}
83
- Human Input: {{human_input}}
84
- {audio_class}:'''
85
-
86
- suffix = f'''Source: {audio_class}
87
- Length of Audio in Seconds: {audio_length}
88
- Human Input: {userText}
89
- {audio_class} Response:'''
90
- template = prefix + suffix
91
-
92
- prompt = PromptTemplate(
93
- input_variables=["history", "human_input"],
94
- template=template
95
- )
96
-
97
- chatgpt_chain = LLMChain(
98
- llm=OpenAI(temperature=.5, openai_api_key=session_token),
99
- prompt=prompt,
100
- verbose=True,
101
- memory=ConversationalBufferWindowMemory(k=2, ai_prefix=audio_class),
102
- )
103
 
104
- output = chatgpt_chain.predict(human_input=message)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
- return output
107
 
 
 
 
 
108
 
109
  demo = gr.Interface(
110
  audio_tag,
@@ -112,7 +112,9 @@ demo = gr.Interface(
112
  gr.Audio(source="upload", type="filepath", label="Your audio"),
113
  gr.Textbox(),
114
  ],
115
- gr.Textbox(),
 
 
116
  title="AnyChat",
117
  description="Non-Human entities have many things to say, listen to them!",
118
- ).launch(debug=True)
 
26
  template = None
27
  prompt = None
28
  chain = None
29
+ formatted_classname = "tree"
30
+ chain =
31
 
32
  def format_classname(classname):
33
  return classname.capitalize()
 
61
  # Print audio tagging top probabilities
62
 
63
  label = labels[sorted_indexes[0]]
64
+ formatted_classname = label
65
+ chain = construct_langchain(formatted_classname)
66
+ return formatted_classname
67
 
68
+ def construct_langchain(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
 
80
 
81
  Let's begin:
82
  Non-human Entity: {audio_class}"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
+ suffix = f'''Source: {audio_class}
85
+ Length of Audio in Seconds: 2 seconds
86
+ Human Input: {userText}
87
+ {audio_class} Response:'''
88
+ template = prefix + suffix
89
+
90
+ prompt = PromptTemplate(
91
+ input_variables=["history", "human_input"],
92
+ template=template
93
+ )
94
+
95
+ chatgpt_chain = LLMChain(
96
+ llm=OpenAI(temperature=.5, openai_api_key=session_token),
97
+ prompt=prompt,
98
+ verbose=True,
99
+ memory=ConversationalBufferWindowMemory(k=2, ai_prefix=audio_class),
100
+ )
101
 
102
+ return chatgpt_chain
103
 
104
+ def predict(input, history=[]):
105
+ formatted_message = chain.predict(human_input=input)
106
+ history.append(formatted_message)
107
+ return formatted_message, history
108
 
109
  demo = gr.Interface(
110
  audio_tag,
 
112
  gr.Audio(source="upload", type="filepath", label="Your audio"),
113
  gr.Textbox(),
114
  ],
115
+ fn=predict,
116
+ inputs=["text", "state"],
117
+ outputs=["chatbot", "state"],
118
  title="AnyChat",
119
  description="Non-Human entities have many things to say, listen to them!",
120
+ ).launch(debug=True)