Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ from groq import Groq
|
|
| 8 |
|
| 9 |
# Fetch API key from environment variable
|
| 10 |
API_KEY = os.environ.get('GroqApi')
|
|
|
|
| 11 |
global CHUNKS, INDEX, MODEL
|
| 12 |
# Initialize global variables
|
| 13 |
CHUNKS = None
|
|
@@ -73,12 +74,25 @@ url = st.text_input("Enter Tariff Data URL", "https://iesco.com.pk/index.php/cus
|
|
| 73 |
if st.button("Process Tariff Data"):
|
| 74 |
with st.spinner("Extracting and processing data..."):
|
| 75 |
try:
|
| 76 |
-
# Declare globals
|
| 77 |
-
|
| 78 |
text = scrape_tariff_data(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
CHUNKS = chunk_text(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
INDEX, embeddings, MODEL = create_faiss_index(CHUNKS)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
st.success("Data processed and indexed!")
|
|
|
|
|
|
|
| 82 |
except Exception as e:
|
| 83 |
st.error(f"Error processing data: {e}")
|
| 84 |
|
|
|
|
| 8 |
|
| 9 |
# Fetch API key from environment variable
|
| 10 |
API_KEY = os.environ.get('GroqApi')
|
| 11 |
+
|
| 12 |
global CHUNKS, INDEX, MODEL
|
| 13 |
# Initialize global variables
|
| 14 |
CHUNKS = None
|
|
|
|
| 74 |
if st.button("Process Tariff Data"):
|
| 75 |
with st.spinner("Extracting and processing data..."):
|
| 76 |
try:
|
| 77 |
+
#global CHUNKS, INDEX, MODEL # Declare globals before modifying
|
|
|
|
| 78 |
text = scrape_tariff_data(url)
|
| 79 |
+
if not text:
|
| 80 |
+
st.error("Failed to scrape data from the provided URL.")
|
| 81 |
+
st.stop()
|
| 82 |
+
|
| 83 |
CHUNKS = chunk_text(text)
|
| 84 |
+
if not CHUNKS:
|
| 85 |
+
st.error("No data available for processing.")
|
| 86 |
+
st.stop()
|
| 87 |
+
|
| 88 |
INDEX, embeddings, MODEL = create_faiss_index(CHUNKS)
|
| 89 |
+
if not INDEX:
|
| 90 |
+
st.error("Failed to create FAISS index.")
|
| 91 |
+
st.stop()
|
| 92 |
+
|
| 93 |
st.success("Data processed and indexed!")
|
| 94 |
+
st.write("Number of chunks processed:", len(CHUNKS))
|
| 95 |
+
|
| 96 |
except Exception as e:
|
| 97 |
st.error(f"Error processing data: {e}")
|
| 98 |
|