Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
|
4 |
+
icons = {"assistant": "robot.png", "user": "man-kddi.png"}
|
5 |
+
|
6 |
+
def streamer(text):
|
7 |
+
for i in text:
|
8 |
+
yield i
|
9 |
+
time.sleep(0.005)
|
10 |
+
|
11 |
+
# Streamlit app initialization
|
12 |
+
st.title("RAG AGENT")
|
13 |
+
st.markdown("RAG Agent with PDF and Web Search")
|
14 |
+
|
15 |
+
if 'messages' not in st.session_state:
|
16 |
+
st.session_state.messages = [{'role': 'assistant', "content": 'Hello! Upload a PDF/Youtube Video link and ask me anything about the content.'}]
|
17 |
+
|
18 |
+
for message in st.session_state.messages:
|
19 |
+
with st.chat_message(message['role'], avatar=icons[message['role']]):
|
20 |
+
st.write(message['content'])
|
21 |
+
|
22 |
+
with st.sidebar:
|
23 |
+
st.title("Menu:")
|
24 |
+
uploaded_file = st.file_uploader("Upload your PDF Files and Click on the Submit & Process Button")
|
25 |
+
video_url = st.text_input("Enter Youtube Video Link: ")
|
26 |
+
if st.button("Submit & Process"):
|
27 |
+
with st.spinner("Processing..."):
|
28 |
+
print("Processing files")
|
29 |
+
|
30 |
+
if uploaded_file:
|
31 |
+
print("File uploaded")
|
32 |
+
|
33 |
+
if video_url:
|
34 |
+
print("Link uploaded:"+video_url)
|
35 |
+
|
36 |
+
st.success("Done")
|
37 |
+
|
38 |
+
user_prompt = st.chat_input("Ask me anything about the content of the PDF or Web Link:")
|
39 |
+
|
40 |
+
if user_prompt and (uploaded_file or video_url):
|
41 |
+
st.session_state.messages.append({'role': 'user', "content": user_prompt})
|
42 |
+
with st.chat_message("user", avatar="man-kddi.png"):
|
43 |
+
st.write(user_prompt)
|
44 |
+
|
45 |
+
# Trigger assistant's response retrieval and update UI
|
46 |
+
with st.spinner("Thinking..."):
|
47 |
+
response = "I have an answer coming soon..."
|
48 |
+
with st.chat_message("user", avatar="robot.png"):
|
49 |
+
st.write_stream(streamer(response))
|
50 |
+
st.session_state.messages.append({'role': 'assistant', "content": response})
|