pkraman06 commited on
Commit
202fb2f
·
verified ·
1 Parent(s): c452585

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +8 -8
src/streamlit_app.py CHANGED
@@ -2,18 +2,15 @@ import streamlit as st
2
  import os
3
  import sys
4
 
5
- # --- FIX: Path handling for Hugging Face Spaces ---
6
- # This ensures that 'src' is in the python path so it can find model_processor.py
7
  current_dir = os.path.dirname(os.path.abspath(__file__))
 
8
  if current_dir not in sys.path:
9
  sys.path.append(current_dir)
10
 
11
- # Now you can import it directly
12
- try:
13
- from model_processor import LlamaProcessor
14
- except ImportError:
15
- # Alternative if the above fails depending on HF environment
16
- from src.model_processor import LlamaProcessor
17
 
18
  st.set_page_config(page_title="Llama PDF Expert", layout="wide")
19
 
@@ -57,6 +54,7 @@ if uploaded_file and token:
57
  st.error(f"Error initializing: {str(e)}")
58
 
59
  # --- Logic: Chat Interface ---
 
60
  for msg in st.session_state.messages:
61
  with st.chat_message(msg["role"]):
62
  st.markdown(msg["content"])
@@ -66,10 +64,12 @@ if prompt := st.chat_input("Ask a question about the PDF..."):
66
  if not st.session_state.vector_db:
67
  st.warning("Please upload a PDF and provide a token first.")
68
  else:
 
69
  st.session_state.messages.append({"role": "user", "content": prompt})
70
  with st.chat_message("user"):
71
  st.markdown(prompt)
72
 
 
73
  with st.chat_message("assistant"):
74
  with st.spinner("Thinking..."):
75
  answer = st.session_state.processor.get_answer(prompt, st.session_state.vector_db)
 
2
  import os
3
  import sys
4
 
5
+ # --- PATH FIX FOR HUGGING FACE ---
6
+ # Get the absolute path of the directory where this file (streamlit_app.py) lives
7
  current_dir = os.path.dirname(os.path.abspath(__file__))
8
+ # Add that directory to the system path so Python can find model_processor.py
9
  if current_dir not in sys.path:
10
  sys.path.append(current_dir)
11
 
12
+ # Now the import will work regardless of the folder structure
13
+ from model_processor import LlamaProcessor
 
 
 
 
14
 
15
  st.set_page_config(page_title="Llama PDF Expert", layout="wide")
16
 
 
54
  st.error(f"Error initializing: {str(e)}")
55
 
56
  # --- Logic: Chat Interface ---
57
+ # Display chat history
58
  for msg in st.session_state.messages:
59
  with st.chat_message(msg["role"]):
60
  st.markdown(msg["content"])
 
64
  if not st.session_state.vector_db:
65
  st.warning("Please upload a PDF and provide a token first.")
66
  else:
67
+ # User message
68
  st.session_state.messages.append({"role": "user", "content": prompt})
69
  with st.chat_message("user"):
70
  st.markdown(prompt)
71
 
72
+ # Assistant response
73
  with st.chat_message("assistant"):
74
  with st.spinner("Thinking..."):
75
  answer = st.session_state.processor.get_answer(prompt, st.session_state.vector_db)