Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,38 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
-
# Load
|
5 |
@st.cache_resource
|
6 |
-
def
|
7 |
-
return pipeline("
|
8 |
|
9 |
-
|
10 |
-
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
|
15 |
-
#
|
16 |
-
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
trump_prompt = f"In the style of Donald Trump: {user_input}"
|
21 |
-
|
22 |
-
# Generate the response with adjusted parameters
|
23 |
-
response = generator(
|
24 |
-
trump_prompt,
|
25 |
-
max_length=30,
|
26 |
-
num_return_sequences=1,
|
27 |
-
do_sample=True,
|
28 |
-
temperature=0.9,
|
29 |
-
top_p=0.85
|
30 |
-
)
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
+
from io import BytesIO
|
4 |
|
5 |
+
# Load Hugging Face models for question-answering and text-to-speech
|
6 |
@st.cache_resource
|
7 |
+
def load_qa_pipeline():
|
8 |
+
return pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
|
9 |
|
10 |
+
@st.cache_resource
|
11 |
+
def load_tts_pipeline():
|
12 |
+
return pipeline("text-to-speech", model="espnet/kan-bayashi-ljspeech-vits")
|
13 |
|
14 |
+
qa_pipeline = load_qa_pipeline()
|
15 |
+
tts_pipeline = load_tts_pipeline()
|
16 |
|
17 |
+
# Streamlit interface
|
18 |
+
st.title("Virtual Assistant")
|
19 |
+
st.write("Ask me anything!")
|
20 |
|
21 |
+
# User query
|
22 |
+
user_query = st.text_input("Type your question here:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
if user_query:
|
25 |
+
# Generate answer using the QA model
|
26 |
+
context = "This is the context of the assistant. The assistant will answer general knowledge questions." # Customize context for better QA accuracy
|
27 |
+
qa_result = qa_pipeline({"question": user_query, "context": context})
|
28 |
+
answer = qa_result['answer']
|
29 |
+
|
30 |
+
# Display answer as text
|
31 |
+
st.write(f"Answer: {answer}")
|
32 |
+
|
33 |
+
# Convert answer to audio using TTS model
|
34 |
+
tts_audio = tts_pipeline(answer, return_tensors="pt").audio
|
35 |
+
|
36 |
+
# Streamlit audio player for TTS output
|
37 |
+
audio_bytes = BytesIO(tts_audio)
|
38 |
+
st.audio(audio_bytes, format="audio/wav")
|