🧠 Science Analyzer
Upload scientific documents and get AI-powered analysis
import gradio as gr from RAG_AGENT import gemini_explain_file, extract_clean_pdf_text import os css = """ .gradio-container { font-family: 'Inter', sans-serif; max-width: 850px !important; margin: auto; padding: 2rem; background-color: #121212; color: #e0e0e0; } .main-header { text-align: center; margin-bottom: 2rem; } .main-header h1 { font-size: 2.2rem; font-weight: 600; color: #ffffff; } .main-header p { font-size: 1rem; color: #bbbbbb; } .upload-area { border: 1px dashed #444 !important; border-radius: 10px !important; background-color: #1e1e1e !important; padding: 1rem; transition: 0.3s; } .upload-area:hover { border-color: #777 !important; } .btn-primary { background-color: #4F46E5 !important; color: white !important; border: none !important; padding: 12px 20px !important; border-radius: 8px !important; font-size: 1rem; font-weight: 500; } .btn-primary:hover { background-color: #3730A3 !important; } #custom-output { background-color: #1e1e1e; border-radius: 10px; padding: 1.5rem; border: 1px solid #333; min-height: 250px; font-size: 1rem; line-height: 1.6; color: #e0e0e0; margin-top: 2rem; } .footer { text-align: center; margin-top: 3rem; font-size: 0.85rem; color: #777; } """ def analyze_file(file, question, analysis_type): if not file: return "⚠️ Please upload a file." if analysis_type == "Extract PDF Text": if not file.name.lower().endswith('.pdf'): return "⚠️ This option only works with PDF files." try: text = extract_clean_pdf_text(file.name) return f"**Extracted Text:**\n\n{text}" except Exception as e: return f"❌ Error: {e}" elif analysis_type == "AI Analysis": if not os.getenv('GEMINI_API_KEY'): return "⚠️ Gemini API key not found in environment." return gemini_explain_file(file, question) return "⚠️ Invalid analysis type." # Gradio UI with gr.Blocks(css=css, title="Science Analyzer - Dark UI") as demo: gr.HTML("""
Upload scientific documents and get AI-powered analysis