Deepak7376 commited on
Commit
f8d987f
1 Parent(s): 5a083f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -49,26 +49,24 @@ def get_file_size(file):
49
  file.seek(0)
50
  return file_size
51
 
52
- # Add a sidebar for model selection
53
  st.sidebar.write("Settings")
54
  st.sidebar.write("-----------")
55
  model_options = ["MBZUAI/LaMini-T5-738M", "google/flan-t5-base", "google/flan-t5-small"]
56
  selected_model = st.sidebar.radio("Choose Model", model_options)
57
  st.sidebar.write("-----------")
58
-
59
  uploaded_file = st.sidebar.file_uploader("Upload file", type=["pdf"])
60
-
61
  st.sidebar.write("-----------")
62
  st.sidebar.write("About Me")
63
  st.sidebar.write("Name: Deepak Yadav")
64
  st.sidebar.write("Bio: Passionate about AI and machine learning. Enjoys working on innovative projects and sharing knowledge with the community.")
65
- st.sidebar.write("[GitHub](https://github.com//deepak7376)")
66
- st.sidebar.write("[LinkedIn](https://www.linkedin.com/in/dky7376)")
67
  st.sidebar.write("-----------")
68
 
69
  @st.cache_resource
70
- def initialize_qa_chain(FILEPATH, CHECKPOINT):
71
- loader = PDFMinerLoader(FILEPATH)
72
  documents = loader.load()
73
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=500)
74
  splits = text_splitter.split_documents(documents)
@@ -105,15 +103,14 @@ def process_answer(instruction, qa_chain):
105
  return generated_text
106
 
107
  if uploaded_file is not None:
108
- file_details = {
109
- "Filename": uploaded_file.name,
110
- "File size": get_file_size(uploaded_file)
111
- }
112
  os.makedirs("docs", exist_ok=True)
113
  filepath = os.path.join("docs", uploaded_file.name)
114
- print(filepath)
 
 
 
115
  with st.spinner('Embeddings are in process...'):
116
- qa_chain = initialize_qa_chain(filepath, selected_model)
117
  else:
118
  qa_chain = None
119
 
 
49
  file.seek(0)
50
  return file_size
51
 
52
+ # Add a sidebar for model selection and user details
53
  st.sidebar.write("Settings")
54
  st.sidebar.write("-----------")
55
  model_options = ["MBZUAI/LaMini-T5-738M", "google/flan-t5-base", "google/flan-t5-small"]
56
  selected_model = st.sidebar.radio("Choose Model", model_options)
57
  st.sidebar.write("-----------")
 
58
  uploaded_file = st.sidebar.file_uploader("Upload file", type=["pdf"])
 
59
  st.sidebar.write("-----------")
60
  st.sidebar.write("About Me")
61
  st.sidebar.write("Name: Deepak Yadav")
62
  st.sidebar.write("Bio: Passionate about AI and machine learning. Enjoys working on innovative projects and sharing knowledge with the community.")
63
+ st.sidebar.write("[GitHub](https://github.com/deepak7376)")
64
+ st.sidebar.write("[LinkedIn](https://www.linkedin.com/in/dky7376/)")
65
  st.sidebar.write("-----------")
66
 
67
  @st.cache_resource
68
+ def initialize_qa_chain(filepath, CHECKPOINT):
69
+ loader = PDFMinerLoader(filepath)
70
  documents = loader.load()
71
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=500)
72
  splits = text_splitter.split_documents(documents)
 
103
  return generated_text
104
 
105
  if uploaded_file is not None:
 
 
 
 
106
  os.makedirs("docs", exist_ok=True)
107
  filepath = os.path.join("docs", uploaded_file.name)
108
+ with open(filepath, "wb") as temp_file:
109
+ temp_file.write(uploaded_file.read())
110
+ temp_filepath = temp_file.name
111
+
112
  with st.spinner('Embeddings are in process...'):
113
+ qa_chain = initialize_qa_chain(temp_filepath, selected_model)
114
  else:
115
  qa_chain = None
116