markytools commited on
Commit
e4b3526
·
1 Parent(s): 6cbfbad
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -1,10 +1,11 @@
1
  import streamlit as st
2
  from tempfile import NamedTemporaryFile
 
3
 
4
  radioButtonList = ["E-commerce CSV (https://www.kaggle.com/datasets/mervemenekse/ecommerce-dataset)",
5
  "Upload my own CSV",
6
  "Upload my own PDF",
7
- "URL Chat with Google Alphabet's 2022 Q2 Earnings Report (https://shorturl.at/csCK3)",
8
  "Enter my own URL"]
9
  genre = st.radio(
10
  "Choose dataset to finetune", radioButtonList
@@ -26,15 +27,17 @@ elif genre==radioButtonList[4]:
26
  pdfCSVURLText = "URL"
27
 
28
  isCustomURL = genre==radioButtonList[4]
29
- title = st.text_input('Enter your own URL', 'https://shorturl.at/csCK3', disabled=not isCustomURL)
30
- st.write('The current movie title is', title)
31
 
32
  isCustomPDF = genre==radioButtonList[1] or genre==radioButtonList[2]
33
  uploaded_file = st.file_uploader(f"Upload your own {pdfCSVURLText} here", type=pdfCSVURLText.lower(), disabled=not isCustomPDF)
 
34
  if uploaded_file is not None:
35
  with NamedTemporaryFile(dir='.', suffix=f'.{pdfCSVURLText.lower()}') as f:
36
  f.write(uploaded_file.getbuffer())
37
- st.write('The current uploaded file is', f.name)
 
38
 
39
 
40
  # # To read file as bytes:
@@ -56,11 +59,17 @@ if uploaded_file is not None:
56
  if genre==radioButtonList[0]:
57
  enableChatBox = True
58
  elif genre==radioButtonList[1]:
 
 
 
 
59
  enableChatBox = True
 
 
60
 
61
- title = st.text_input(f'Ask me anything about this {pdfCSVURLText}', '', placeholder="Type your question here (e.g. what was the most sold item?)", disabled=not isCustomURL)
62
  chatWithPDFButton = "CLICK HERE TO START CHATTING"
63
- if st.button(chatWithPDFButton, type="primary"):
64
  pass
65
  else:
66
  pass
 
1
  import streamlit as st
2
  from tempfile import NamedTemporaryFile
3
+ import validators
4
 
5
  radioButtonList = ["E-commerce CSV (https://www.kaggle.com/datasets/mervemenekse/ecommerce-dataset)",
6
  "Upload my own CSV",
7
  "Upload my own PDF",
8
+ "URL Chat with Google Alphabet's 2022 Q2 Earnings Report (https://tinyurl.com/f85wujsj)",
9
  "Enter my own URL"]
10
  genre = st.radio(
11
  "Choose dataset to finetune", radioButtonList
 
27
  pdfCSVURLText = "URL"
28
 
29
  isCustomURL = genre==radioButtonList[4]
30
+ urlInput = st.text_input('Enter your own URL', '', placeholder="Type your URL here (e.g. https://tinyurl.com/f85wujsj)", disabled=not isCustomURL)
31
+ isValidURL = validators.url(urlInput)
32
 
33
  isCustomPDF = genre==radioButtonList[1] or genre==radioButtonList[2]
34
  uploaded_file = st.file_uploader(f"Upload your own {pdfCSVURLText} here", type=pdfCSVURLText.lower(), disabled=not isCustomPDF)
35
+ uploadedFilename = ""
36
  if uploaded_file is not None:
37
  with NamedTemporaryFile(dir='.', suffix=f'.{pdfCSVURLText.lower()}') as f:
38
  f.write(uploaded_file.getbuffer())
39
+ uploadedFilename = f.name
40
+ # st.write('The current uploaded file is', f.name)
41
 
42
 
43
  # # To read file as bytes:
 
59
  if genre==radioButtonList[0]:
60
  enableChatBox = True
61
  elif genre==radioButtonList[1]:
62
+ enableChatBox = uploadedFilename[-4:]==".csv"
63
+ elif genre==radioButtonList[2]:
64
+ enableChatBox = uploadedFilename[-4:]==".pdf"
65
+ elif genre==radioButtonList[3]:
66
  enableChatBox = True
67
+ elif genre==radioButtonList[4]:
68
+ enableChatBox = isValidURL
69
 
70
+ title = st.text_input(f'Ask me anything about this {pdfCSVURLText}', '', placeholder="Type your question here (e.g. what was the most sold item?)", disabled=not enableChatBox)
71
  chatWithPDFButton = "CLICK HERE TO START CHATTING"
72
+ if st.button(chatWithPDFButton, type="primary", disabled=not enableChatBox):
73
  pass
74
  else:
75
  pass