import os import streamlit as st from dotenv import load_dotenv import socket from groq import Groq from scholarly import scholarly from prompts import get_research_prompt, get_guidance_prompt, invalid_question_prompt # Load environment variables from (.env) file load_dotenv() # Set up Groq client using st.secrets for secure API key handling # api_key = st.secrets["GROQ_API_KEY"] # Haalt API key uit een toml file (hier niet van toepassing) # groq_api_key = os.environ['GROQ_API_KEY'] # Dit is de methode om de GROQ API key op te halen in HF Spaces omgeving groq_api_key = os.environ['GROQ_API_KEY'] # print("groq_api_key: ", groq_api_key) if not groq_api_key: st.error("GROQ_API_KEY not found. Please check your environment variables.") else: client = Groq(api_key=groq_api_key) # Function to check internet connection def is_connected(): try: socket.create_connection(("www.google.com", 80)) return True except OSError: return False # Streamlit UI Enhancements st.set_page_config(page_title="AI Researcher Pro - Your Research Companion", layout="wide") # Custom CSS for styling st.markdown(""" """, unsafe_allow_html=True) # Title and subtitle with custom styling st.markdown("
Your AI-powered research assistant for all your research needs!
", unsafe_allow_html=True) # Adding a tooltip with enhanced styling st.markdown("""Tip: Ask specific research questions like "What are the latest trends in AI?" or "How to improve model accuracy in NLP?"
""", unsafe_allow_html=True) # Connectivity Check if not is_connected(): st.error("⚠️ No internet connection. Please check your internet and try again.") st.stop() # Define fields and their respective sub-fields fields_dict = { "Computer Science": ["Artificial Intelligence", "Machine Learning", "Data Science", "Computer Vision", "Natural Language Processing"], "Medical": ["Biotechnology", "Genetics", "Neuroscience", "Immunology", "Medical Imaging"], "Physics": ["Quantum Mechanics", "Astrophysics", "Nuclear Physics", "Condensed Matter Physics", "Particle Physics"], "Chemistry": ["Organic Chemistry", "Inorganic Chemistry", "Biochemistry", "Physical Chemistry", "Analytical Chemistry"], "Engineering": ["Electrical Engineering", "Mechanical Engineering", "Civil Engineering", "Aerospace Engineering", "Biomedical Engineering"] } # Sidebar for selecting broad research fields st.sidebar.markdown(" ", unsafe_allow_html=True) broad_field = st.sidebar.selectbox("Research Field", list(fields_dict.keys())) # Show relevant sub-fields based on the broad field selected st.sidebar.markdown(f" ", unsafe_allow_html=True) selected_subfields = [] for subfield in fields_dict[broad_field]: if st.sidebar.checkbox(f"🔍 {subfield}", key=subfield): selected_subfields.append(subfield) # User input in the main layout st.markdown("