Update app.py
Browse files
app.py
CHANGED
@@ -21,18 +21,6 @@ def transcribe(audio):
|
|
21 |
|
22 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
23 |
|
24 |
-
def client_fn(model):
|
25 |
-
if "Mixtral" in model:
|
26 |
-
return InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
27 |
-
elif "Llama" in model:
|
28 |
-
return InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
|
29 |
-
elif "Mistral" in model:
|
30 |
-
return InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
|
31 |
-
elif "Phi" in model:
|
32 |
-
return InferenceClient("microsoft/Phi-3-mini-4k-instruct")
|
33 |
-
else:
|
34 |
-
return InferenceClient("microsoft/Phi-3-mini-4k-instruct")
|
35 |
-
|
36 |
def randomize_seed_fn(seed: int) -> int:
|
37 |
seed = random.randint(0, 999999)
|
38 |
return seed
|
@@ -45,18 +33,17 @@ Respond in a normal, conversational manner while being friendly and helpful.
|
|
45 |
[USER]
|
46 |
"""
|
47 |
|
48 |
-
def models(text,
|
49 |
-
|
50 |
seed = int(randomize_seed_fn(seed))
|
51 |
-
generator = torch.Generator().manual_seed(seed)
|
52 |
-
|
53 |
-
client =
|
54 |
-
|
55 |
generate_kwargs = dict(
|
56 |
max_new_tokens=300,
|
57 |
seed=seed
|
58 |
)
|
59 |
-
|
60 |
formatted_prompt = system_instructions1 + text + "[JARVIS]"
|
61 |
stream = client.text_generation(
|
62 |
formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
@@ -76,32 +63,23 @@ async def respond(audio, model, seed):
|
|
76 |
await communicate.save(tmp_path)
|
77 |
return tmp_path
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
audio_file = st.file_uploader("Upload Audio", type=["wav", "mp3"], key="voice_audio")
|
86 |
-
submit_button = st.form_submit_button("Submit")
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
tmp_file.write(audio_bytes)
|
94 |
-
tmp_path = tmp_file.name
|
95 |
-
response = respond(tmp_path, model_choice, 42)
|
96 |
-
st.audio(response, format='audio/wav')
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
user_text = st.text_area("Enter your message:", key="text_input")
|
101 |
-
submit_button = st.form_submit_button("Submit")
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
response = models(user_text, model_choice, 42)
|
107 |
-
st.text_area("JARVIS Response", value=response, key="text_output", height=150)
|
|
|
21 |
|
22 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def randomize_seed_fn(seed: int) -> int:
|
25 |
seed = random.randint(0, 999999)
|
26 |
return seed
|
|
|
33 |
[USER]
|
34 |
"""
|
35 |
|
36 |
+
def models(text, seed=42):
|
|
|
37 |
seed = int(randomize_seed_fn(seed))
|
38 |
+
generator = torch.Generator().manual_seed(seed)
|
39 |
+
|
40 |
+
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
|
41 |
+
|
42 |
generate_kwargs = dict(
|
43 |
max_new_tokens=300,
|
44 |
seed=seed
|
45 |
)
|
46 |
+
|
47 |
formatted_prompt = system_instructions1 + text + "[JARVIS]"
|
48 |
stream = client.text_generation(
|
49 |
formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
|
|
63 |
await communicate.save(tmp_path)
|
64 |
return tmp_path
|
65 |
|
66 |
+
DESCRIPTION = """ # <center><b>JARVIS⚡</b></center>
|
67 |
+
### <center>A personal Assistant of Tony Stark for YOU
|
68 |
+
### <center>Voice Chat with your personal Assistant</center>
|
69 |
+
"""
|
70 |
|
71 |
+
st.markdown(DESCRIPTION)
|
72 |
+
st.title("JARVIS")
|
|
|
|
|
73 |
|
74 |
+
uploaded_file = st.file_uploader("Upload audio file", type=["wav"])
|
75 |
+
seed = st.slider("Seed", min_value=0, max_value=999999, value=0)
|
76 |
+
if uploaded_file is not None:
|
77 |
+
# Convert the uploaded file to a BytesIO object
|
78 |
+
audio_bytes = uploaded_file.read()
|
|
|
|
|
|
|
|
|
79 |
|
80 |
+
# Process the audio using the respond function
|
81 |
+
response_path = asyncio.run(respond(audio_bytes, models, seed))
|
|
|
|
|
82 |
|
83 |
+
# Display the audio response
|
84 |
+
st.audio(response_path, format="audio/wav")
|
85 |
+
os.remove(response_path)
|
|
|
|