Spaces:
Sleeping
Sleeping
GitsSaikat commited on
Update app.py
Browse files10 unmodified lines1112131415161718192021222324252627289 unmodified lines3839404142434445464723 unmodified lines717273747576774 unmodified lines828384858687881 unmodified line9091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420510 unmodified linesinitial_sidebar_state="expanded")# Load and display logo in sidebarlogo = Image.open('logo.png')st.sidebar.image(logo, width=200, use_container_width=True)# Initialize session state for API keysif 'api_keys_configured' not in st.session_state:st.session_state.api_keys_configured = False# Custom CSS (previous CSS remains the same)st.markdown("""<style>/* ... previous CSS ... */.api-container {background-color: #f8f9fa;padding: 1.5rem;9 unmodified lines</style>""", unsafe_allow_html=True)# Sidebar for API Configurationwith st.sidebar:st.markdown("### βοΈ API Configuration")st.info("Please configure your API keys before starting research.")with st.expander("Configure API Keys", expanded=not st.session_state.api_keys_configured):api_form = st.form("api_keys_form")23 unmodified linesif not all([openrouter_key, serpapi_key, jina_key]):st.error("β All API keys are required!")else:# Store API keys in session statest.session_state.openrouter_key = openrouter_keyst.session_state.serpapi_key = serpapi_keyst.session_state.jina_key = jina_key4 unmodified linesif st.session_state.api_keys_configured:st.success("β API Keys configured")# Add links to get API keysst.markdown("### π Get API Keys")st.markdown("""- [OpenRouter API Key](https://openrouter.ai/keys)1 unmodified line- [Jina API Key](https://jina.ai/api-key)""")def run_research(user_query, iteration_limit):# Set API keys in the research moduledeep_research.OPENROUTER_API_KEY = st.session_state.openrouter_keydeep_research.SERPAPI_API_KEY = st.session_state.serpapi_keydeep_research.JINA_API_KEY = st.session_state.jina_keyreturn asyncio.run(deep_research.research_flow(user_query, iteration_limit))# Main contentif not st.session_state.api_keys_configured:st.warning("β οΈ Please configure your API keys in the sidebar before proceeding.")else:# Title and descriptionst.title("π Open DeepResearch")st.markdown("""<div style='background-color: #e3f2fd; padding: 1rem; border-radius: 10px; margin-bottom: 2rem;'><h4 style='color: #1565C0; margin-bottom: 0.5rem;'>Welcome to the Open DeepResearch!</h4><p style='color: #424242;'>This application helps you conduct comprehensive research on any topic by:<br>β’ Generating relevant search queries<br>β’ Analyzing multiple sources<br>β’ Synthesizing information into a detailed report</p></div>""", unsafe_allow_html=True)# Main form in a containerwith st.container():col1, col2 = st.columns([2, 1])with col1:with st.form("research_form", clear_on_submit=False):st.markdown("### Research Parameters")user_query = st.text_area("Research Query",placeholder="Enter your research topic or question here...",help="Be as specific as possible for better results",height=100)col_a, col_b = st.columns(2)with col_a:iter_limit_input = st.number_input("Maximum Iterations",min_value=1,max_value=20,value=10,help="Higher values mean more thorough research but longer processing time")submitted = st.form_submit_button("π Start Research")with col2:st.markdown("### Tips for Better Results")st.info("""β’ Be specific in your queryβ’ Use clear, focused questionsβ’ Consider including relevant keywordsβ’ Specify time periods if applicable""")# Process and display resultsif submitted:if not user_query.strip():st.error("β οΈ Please enter a research query before proceeding.")else:try:with st.spinner("π Conducting research... This may take a few minutes..."):final_report = run_research(user_query, int(iter_limit_input))st.markdown("""<div class='report-container'><h3 style='color: #1E88E5; margin-bottom: 1rem;'>π Research Report</h3></div>""", unsafe_allow_html=True)# Display the report in tabstab1, tab2 = st.tabs(["π Formatted Report", "π Raw Text"])with tab1:st.markdown(final_report)with tab2:st.text_area(label="",value=final_report,height=500,help="You can copy the raw text from here")# Download button for the reportst.download_button(label="π₯ Download Report",data=final_report,file_name="research_report.txt",mime="text/plain")except Exception as e:st.error(f"β An error occurred during research: {str(e)}")st.markdown("""<div style='background-color: #ffebee; padding: 1rem; border-radius: 10px;'><p style='color: #c62828;'>Please try again with a different query or contact support if the issue persists.</p></div>""", unsafe_allow_html=True)# Footerst.markdown("""<div style='text-align: center; color: #666; padding: 2rem;'><p>Built by GitsSaikat β€οΈ</p></div>""", unsafe_allow_html=True)10 unmodified lines11121314151617181920212223242526272829309 unmodified lines404142434445464748495051525323 unmodified lines7778798081824 unmodified lines8788899091921 unmodified line94959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721810 unmodified linesinitial_sidebar_state="expanded")# Load imageslogo = Image.open('logo.png')banner = Image.open('banner.png')# Display banner at top# st.image(banner, use_container_width=True)# Custom CSSst.markdown("""<style>.stImage > img {border-radius: 10px;margin-bottom: 2rem;}.api-container {background-color: #f8f9fa;padding: 1.5rem;9 unmodified lines</style>""", unsafe_allow_html=True)# Initialize session stateif 'api_keys_configured' not in st.session_state:st.session_state.api_keys_configured = False# Sidebar configurationwith st.sidebar:st.image(logo, width=200, use_container_width=True)st.markdown("### βοΈ API Configuration")with st.expander("Configure API Keys", expanded=not st.session_state.api_keys_configured):api_form = st.form("api_keys_form")23 unmodified linesif not all([openrouter_key, serpapi_key, jina_key]):st.error("β All API keys are required!")else:st.session_state.openrouter_key = openrouter_keyst.session_state.serpapi_key = serpapi_keyst.session_state.jina_key = jina_key4 unmodified linesif st.session_state.api_keys_configured:st.success("β API Keys configured")st.markdown("### π Get API Keys")st.markdown("""- [OpenRouter API Key](https://openrouter.ai/keys)1 unmodified line- [Jina API Key](https://jina.ai/api-key)""")def run_research(user_query, iteration_limit, search_limit):deep_research.OPENROUTER_API_KEY = st.session_state.openrouter_keydeep_research.SERPAPI_API_KEY = st.session_state.serpapi_keydeep_research.JINA_API_KEY = st.session_state.jina_keyreturn asyncio.run(deep_research.research_flow(user_query, iteration_limit, search_limit))# Main contentst.title("π Open DeepResearch")st.markdown("""<div style='background-color: #5dade2; padding: 1rem; border-radius: 10px; margin-bottom: 2rem;'><h4 style='color: #1565C0; margin-bottom: 0.5rem;'>Welcome to the Open DeepResearch!</h4><p style='color: #424242;'>This application helps you conduct comprehensive research on any topic by:<br>β’ Generating relevant search queries<br>β’ Analyzing multiple sources<br>β’ Synthesizing information into a detailed report</p></div>""", unsafe_allow_html=True)with st.container():col1, col2 = st.columns([2, 1])with col1:with st.form("research_form", clear_on_submit=False):st.markdown("### Research Parameters")user_query = st.text_area("Research Query",placeholder="Enter your research topic or question here...",help="Be as specific as possible for better results",height=100,disabled=not st.session_state.api_keys_configured)col_a, col_b = st.columns(2)with col_a:iter_limit_input = st.number_input("Maximum Iterations",min_value=1,max_value=20,value=10,help="Higher values mean more thorough research but longer processing time",disabled=not st.session_state.api_keys_configured)with col_b:search_limit_input = st.number_input("Results Per Search",min_value=1,max_value=20,value=5,help="Number of results per search. Lower values reduce token usage",disabled=not st.session_state.api_keys_configured)submitted = st.form_submit_button("π Start Research",disabled=not st.session_state.api_keys_configured)with col2:st.markdown("### Tips for Better Results")st.info("""β’ Be specific in your queryβ’ Use clear, focused questionsβ’ Consider including relevant keywordsβ’ Specify time periods if applicableβ’ Lower search results reduce token usage""")if not st.session_state.api_keys_configured:st.warning("β οΈ Please configure your API keys in the sidebar to enable research.")if submitted and st.session_state.api_keys_configured:if not user_query.strip():st.error("β οΈ Please enter a research query before proceeding.")else:try:with st.spinner("π Conducting research... This may take a few minutes..."):final_report = run_research(user_query, int(iter_limit_input), int(search_limit_input))st.markdown("""<div class='report-container'><h3 style='color: #1E88E5; margin-bottom: 1rem;'>π Research Report</h3></div>""", unsafe_allow_html=True)tab1, tab2 = st.tabs(["π Formatted Report", "π Raw Text"])with tab1:st.markdown(final_report)with tab2:st.text_area(label="",value=final_report,height=500,help="You can copy the raw text from here")st.download_button(label="π₯ Download Report",data=final_report,file_name="research_report.txt",mime="text/plain")except Exception as e:st.error(f"β An error occurred during research: {str(e)}")st.markdown("""<div style='background-color: #ffebee; padding: 1rem; border-radius: 10px;'><p style='color: #c62828;'>Please try again with a different query or contact support if the issue persists.</p></div>""", unsafe_allow_html=True)st.markdown("""<div style='text-align: center; color: #666; padding: 2rem;'><p>Built by GitsSaikat β€οΈ</p></div>""", unsafe_allow_html=True)
app.py+123-110