Spaces:
Runtime error
Runtime error
Commit
·
320951c
1
Parent(s):
35c9479
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import numpy as np
|
|
@@ -10,6 +12,9 @@ from efficientat.helpers.utils import NAME_TO_WIDTH, labels
|
|
| 10 |
from torch import autocast
|
| 11 |
from contextlib import nullcontext
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
MODEL_NAME = "mn40_as"
|
| 14 |
|
| 15 |
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
|
|
@@ -44,41 +49,48 @@ def audio_tag(
|
|
| 44 |
sorted_indexes = np.argsort(preds)[::-1]
|
| 45 |
output = {}
|
| 46 |
# Print audio tagging top probabilities
|
| 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 |
-
|
| 77 |
-
|
| 78 |
-
else:
|
| 79 |
-
return Sorry, I'm quite busy right now, but please try again later :)
|
| 80 |
-
"""
|
| 81 |
-
return message
|
| 82 |
|
| 83 |
|
| 84 |
demo = gr.Interface(
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
import torch
|
| 5 |
import numpy as np
|
|
|
|
| 12 |
from torch import autocast
|
| 13 |
from contextlib import nullcontext
|
| 14 |
|
| 15 |
+
from langchain import OpenAI, ConversationChain, LLMChain, PromptTemplate
|
| 16 |
+
from langchain.chains.conversation.memory import ConversationalBufferWindowMemory
|
| 17 |
+
|
| 18 |
MODEL_NAME = "mn40_as"
|
| 19 |
|
| 20 |
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
|
|
|
|
| 49 |
sorted_indexes = np.argsort(preds)[::-1]
|
| 50 |
output = {}
|
| 51 |
# Print audio tagging top probabilities
|
| 52 |
+
|
| 53 |
+
label = labels[sorted_indexes[0]]
|
| 54 |
+
return formatted_message(label)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
cached_audio_class = None
|
| 58 |
+
template = None
|
| 59 |
+
prompt = None
|
| 60 |
+
chain = None
|
| 61 |
+
|
| 62 |
+
def formatted_message(audio_class):
|
| 63 |
+
if cached_audio_class != audio_class:
|
| 64 |
+
cached_audio_class = audio_class
|
| 65 |
|
| 66 |
+
prefix = '''You are going to act as a magical tool that allows for humans to communicate with non-human entities like
|
| 67 |
+
rocks, crackling fire, trees, animals, and the wind. In order to do this, we're going to provide you a data string which
|
| 68 |
+
represents the audio input, the source of the audio, and the human's text input for the conversation.
|
| 69 |
+
The goal is for you to embody the source of the audio, and use the length and variance in the signal data to produce
|
| 70 |
+
plausible responses to the humans input. Remember to embody the the source data. When we start the conversation,
|
| 71 |
+
you should generate a "personality profile" for the source and utilize that personality profile in your responses.
|
| 72 |
+
Let's begin:'''
|
| 73 |
+
suffix = f'''Source: {audio_class}
|
| 74 |
+
Length of Audio in Seconds: {audio_length}
|
| 75 |
+
Human Input: {userText}
|
| 76 |
+
{audio_class} Response:'''
|
| 77 |
+
template = prefix + suffix
|
| 78 |
+
|
| 79 |
+
prompt = PromptTemplate(
|
| 80 |
+
input_variables=["history", "human_input"],
|
| 81 |
+
template=template
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
chatgpt_chain = LLMChain(
|
| 85 |
+
llm=OpenAI(temperature=.5, openai_api_key=session_token),
|
| 86 |
+
prompt=prompt,
|
| 87 |
+
verbose=True,
|
| 88 |
+
memory=ConversationalBufferWindowMemory(k=2),
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
output = chatgpt_chain.predict(human_input=message)
|
| 92 |
+
|
| 93 |
+
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
demo = gr.Interface(
|