Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -27,17 +27,29 @@ if uploaded_file:
|
|
27 |
|
28 |
st.success("PDF Uploaded and Processed Successfully!")
|
29 |
|
30 |
-
#
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
if user_question:
|
34 |
st.write("Processing your question...")
|
35 |
|
36 |
-
# Send the question to Groq API
|
37 |
try:
|
38 |
chat_completion = client.chat.completions.create(
|
39 |
messages=[
|
40 |
-
{"role": "user", "content": f"Context: {
|
41 |
],
|
42 |
model="llama3-8b-8192",
|
43 |
)
|
|
|
27 |
|
28 |
st.success("PDF Uploaded and Processed Successfully!")
|
29 |
|
30 |
+
# Split text into chunks to handle token limits
|
31 |
+
chunk_size = 5000 # Number of characters per chunk
|
32 |
+
chunks = [constitution_text[i:i+chunk_size] for i in range(0, len(constitution_text), chunk_size)]
|
33 |
+
|
34 |
+
# Let user select a chunk to ask questions about
|
35 |
+
st.write("The document is too large, so it's split into smaller parts. Select one to ask questions:")
|
36 |
+
selected_chunk = st.selectbox("Select a part of the document:", range(len(chunks)))
|
37 |
+
current_chunk = chunks[selected_chunk]
|
38 |
+
|
39 |
+
st.write("You selected part:", selected_chunk + 1)
|
40 |
+
st.text_area("Selected Text Segment", current_chunk, height=200)
|
41 |
+
|
42 |
+
# Ask a question about the selected chunk
|
43 |
+
user_question = st.text_input("Ask a question about the selected part:")
|
44 |
+
|
45 |
if user_question:
|
46 |
st.write("Processing your question...")
|
47 |
|
48 |
+
# Send the selected chunk and question to Groq API
|
49 |
try:
|
50 |
chat_completion = client.chat.completions.create(
|
51 |
messages=[
|
52 |
+
{"role": "user", "content": f"Context: {current_chunk}\nQuestion: {user_question}"}
|
53 |
],
|
54 |
model="llama3-8b-8192",
|
55 |
)
|