Spaces:
Sleeping
Sleeping
Commit
·
48b7a28
1
Parent(s):
679d006
bug fix
Browse files
app.py
CHANGED
|
@@ -188,6 +188,58 @@ def create_connected_mode_ui():
|
|
| 188 |
|
| 189 |
return demo
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
def create_story_mode_ui():
|
| 192 |
"""Creates the Gradio UI for the Farmer's Story Mode."""
|
| 193 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="yellow")) as demo:
|
|
@@ -260,12 +312,18 @@ if __name__ == "__main__":
|
|
| 260 |
else:
|
| 261 |
print("⚠️ Connected Mode disabled: ADK components not initialized.")
|
| 262 |
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
document_analysis_ui = create_document_analysis_ui()
|
| 265 |
interface_list.append(document_analysis_ui)
|
| 266 |
tab_titles.append("Document Analysis")
|
| 267 |
-
|
| 268 |
-
print("⚠️ Farmer's Story Mode disabled: Story LLM not initialized.")
|
| 269 |
else:
|
| 270 |
print("❌ No internet connection. Launching in Offline Mode only.")
|
| 271 |
|
|
|
|
| 188 |
|
| 189 |
return demo
|
| 190 |
|
| 191 |
+
def create_document_analysis_ui():
|
| 192 |
+
"""Creates the Gradio UI for the Document Analysis Mode."""
|
| 193 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="pink")) as demo:
|
| 194 |
+
gr.Markdown("# 🌽 Aura Mind Glow: Document Analysis Mode 📄")
|
| 195 |
+
gr.Markdown("Upload a PDF or a spreadsheet and ask questions about its content.")
|
| 196 |
+
|
| 197 |
+
with gr.Row():
|
| 198 |
+
with gr.Column(scale=1):
|
| 199 |
+
doc_input = gr.File(label="Upload Document", file_types=[".pdf", ".csv"])
|
| 200 |
+
query_input = gr.Textbox(label="Ask a question about the document")
|
| 201 |
+
submit_btn = gr.Button("Analyze and Query")
|
| 202 |
+
with gr.Column(scale=2):
|
| 203 |
+
answer_output = gr.Textbox(label="Answer", interactive=False, lines=10)
|
| 204 |
+
status_output = gr.Textbox(label="Status", interactive=False, lines=3)
|
| 205 |
+
|
| 206 |
+
def analysis_process(doc, query):
|
| 207 |
+
if doc is None:
|
| 208 |
+
yield "Please upload a document to begin.", ""
|
| 209 |
+
return
|
| 210 |
+
|
| 211 |
+
file_path = doc.name
|
| 212 |
+
file_ext = os.path.splitext(file_path)[1].lower()
|
| 213 |
+
|
| 214 |
+
if file_ext == ".pdf":
|
| 215 |
+
yield "Analyzing PDF...", ""
|
| 216 |
+
chain, vector_store = analyze_pdf(file_path)
|
| 217 |
+
if chain and vector_store:
|
| 218 |
+
yield "PDF analyzed successfully. Now querying...", ""
|
| 219 |
+
answer = query_pdf(chain, vector_store, query)
|
| 220 |
+
yield answer, "Query complete."
|
| 221 |
+
else:
|
| 222 |
+
yield "Failed to analyze PDF.", "Error"
|
| 223 |
+
elif file_ext == ".csv":
|
| 224 |
+
yield "Analyzing spreadsheet...", ""
|
| 225 |
+
agent = analyze_spreadsheet(file_path)
|
| 226 |
+
if agent:
|
| 227 |
+
yield "Spreadsheet analyzed successfully. Now querying...", ""
|
| 228 |
+
answer = query_spreadsheet(agent, query)
|
| 229 |
+
yield answer, "Query complete."
|
| 230 |
+
else:
|
| 231 |
+
yield "Failed to analyze spreadsheet.", "Error"
|
| 232 |
+
else:
|
| 233 |
+
yield "Unsupported file type. Please upload a PDF or a CSV file.", "Error"
|
| 234 |
+
|
| 235 |
+
submit_btn.click(
|
| 236 |
+
analysis_process,
|
| 237 |
+
inputs=[doc_input, query_input],
|
| 238 |
+
outputs=[answer_output, status_output]
|
| 239 |
+
)
|
| 240 |
+
return demo
|
| 241 |
+
|
| 242 |
+
|
| 243 |
def create_story_mode_ui():
|
| 244 |
"""Creates the Gradio UI for the Farmer's Story Mode."""
|
| 245 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="yellow")) as demo:
|
|
|
|
| 312 |
else:
|
| 313 |
print("⚠️ Connected Mode disabled: ADK components not initialized.")
|
| 314 |
|
| 315 |
+
if STORY_LLM:
|
| 316 |
+
story_mode_ui = create_story_mode_ui()
|
| 317 |
+
interface_list.append(story_mode_ui)
|
| 318 |
+
tab_titles.append("Farmer's Story Mode")
|
| 319 |
+
else:
|
| 320 |
+
print("⚠️ Farmer's Story Mode disabled: Story LLM not initialized.")
|
| 321 |
+
|
| 322 |
+
# Add the new Document Analysis UI
|
| 323 |
document_analysis_ui = create_document_analysis_ui()
|
| 324 |
interface_list.append(document_analysis_ui)
|
| 325 |
tab_titles.append("Document Analysis")
|
| 326 |
+
|
|
|
|
| 327 |
else:
|
| 328 |
print("❌ No internet connection. Launching in Offline Mode only.")
|
| 329 |
|