Spaces:
Sleeping
Sleeping
File size: 4,476 Bytes
f1586e3 5a09d5c 3af593c ee1b548 5a09d5c 3af593c f1586e3 3af593c 87866cd 3af593c 4660a83 3af593c ee1b548 3af593c 87866cd 3af593c 8f85101 ee1b548 3af593c ee1b548 5771d92 3af593c ee1b548 3af593c ee1b548 3af593c ee1b548 3af593c ee1b548 3af593c ee1b548 3af593c f1586e3 87866cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
import streamlit as st
import logging
from services.research_fetcher import ResearchFetcher
from services.model_handler import ModelHandler
from utils.text_processor import TextProcessor
from typing import List
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
class AutismResearchApp:
def __init__(self):
"""Initialize the application components"""
self.research_fetcher = ResearchFetcher()
self.model_handler = ModelHandler()
self.text_processor = TextProcessor()
def _setup_streamlit(self):
"""Setup Streamlit UI components"""
st.title("𧩠AMA Autism")
st.subheader("Your one-stop shop for autism research!")
st.markdown("""
Ask questions about autism research, and I'll analyze recent papers to provide evidence-based answers.
""")
def _fetch_research(self, query: str):
"""Fetch research papers for the given query"""
papers = self.research_fetcher.fetch_all_papers(query)
if not papers:
st.warning("No relevant research papers found. Please try a different search term.")
return None
return papers
def _display_sources(self, papers: List):
"""Display the source papers used to generate the answer"""
st.markdown("### Sources")
for i, paper in enumerate(papers, 1):
st.markdown(f"**{i}. [{paper.title}]({paper.url})**")
# Create three columns for metadata
col1, col2, col3 = st.columns(3)
with col1:
if paper.authors:
st.markdown(f"π₯ Authors: {paper.authors}")
with col2:
st.markdown(f"π
Published: {paper.publication_date}")
with col3:
st.markdown(f"π Source: {paper.source}")
# Show abstract in expander
with st.expander("π View Abstract"):
st.markdown(paper.abstract)
if i < len(papers): # Add separator between papers except for the last one
st.divider()
def run(self):
"""Run the main application loop"""
self._setup_streamlit()
# Initialize session state for papers
if 'papers' not in st.session_state:
st.session_state.papers = []
# Get user query
query = st.text_input("What would you like to know about autism?")
if query:
# Show status while processing
with st.status("Processing your question...") as status:
# Fetch papers
status.write("π Searching for relevant research papers...")
try:
papers = self.research_fetcher.fetch_all_papers(query)
except Exception as e:
st.error(f"Error fetching research papers: {str(e)}")
return
if not papers:
st.warning("No relevant papers found. Please try a different query.")
return
# Generate and validate answer
status.write("π Analyzing research papers...")
context = self.text_processor.create_context(papers)
status.write("βοΈ Generating answer...")
answer = self.model_handler.generate_answer(query, context)
status.write("β
Validating answer...")
is_valid, validation_message = self.model_handler.validate_answer(answer, context)
status.write("β¨ All done! Displaying results...")
# Display results
if is_valid:
st.success("β
Research analysis complete! The answer has been validated for accuracy.")
else:
st.warning("β οΈ The answer may contain information not fully supported by the research.")
st.markdown("### Answer")
st.markdown(answer)
st.markdown("### Validation")
st.info(f"π {validation_message}")
st.divider()
self._display_sources(papers)
def main():
app = AutismResearchApp()
app.run()
if __name__ == "__main__":
main() |