Spaces:
Running
Running
louiecerv
commited on
Commit
·
7f1a08b
1
Parent(s):
7404ad7
Fixed minor bugs
Browse files
app.py
CHANGED
@@ -42,7 +42,7 @@ if uploaded_file is not None:
|
|
42 |
mime_type = "application/pdf"
|
43 |
else:
|
44 |
st.error("Unsupported file type. Please upload an image or PDF.")
|
45 |
-
|
46 |
|
47 |
# Reset chat history when a new file is uploaded
|
48 |
reset_chat()
|
@@ -60,21 +60,22 @@ if uploaded_file is not None:
|
|
60 |
for message in st.session_state.messages:
|
61 |
with st.chat_message(message["role"]):
|
62 |
st.markdown(message["content"])
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
st.
|
|
|
|
42 |
mime_type = "application/pdf"
|
43 |
else:
|
44 |
st.error("Unsupported file type. Please upload an image or PDF.")
|
45 |
+
st.stop()
|
46 |
|
47 |
# Reset chat history when a new file is uploaded
|
48 |
reset_chat()
|
|
|
60 |
for message in st.session_state.messages:
|
61 |
with st.chat_message(message["role"]):
|
62 |
st.markdown(message["content"])
|
63 |
+
|
64 |
+
with st.spinner("Processing..."):
|
65 |
+
# Upload the file with the correct MIME type
|
66 |
+
file_data = genai.upload_file(uploaded_file, mime_type=mime_type)
|
67 |
+
|
68 |
+
# Send file and prompt to Gemini API
|
69 |
+
response = model.generate_content(
|
70 |
+
[
|
71 |
+
user_input,
|
72 |
+
file_data
|
73 |
+
]
|
74 |
+
)
|
75 |
+
|
76 |
+
# Add Gemini response to chat history
|
77 |
+
st.session_state.messages.append({"role": "assistant", "content": response.text})
|
78 |
+
|
79 |
+
# Display Gemini response
|
80 |
+
with st.chat_message("assistant"):
|
81 |
+
st.markdown(response.text)
|