import streamlit as st from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline # Set page configuration st.set_page_config( page_title="Question Answering App", page_icon="❓", layout="centered", initial_sidebar_state="auto", ) # Page title with custom style st.markdown( """

📚 Question Answering App

Enter a context and question to get precise answers powered by AI.

""", unsafe_allow_html=True, ) # Sidebar for model settings and context input st.sidebar.header("Model Settings") model_checkpoint = st.sidebar.text_input( "Model Checkpoint", "Diezu/viedumrc", help="Specify the model checkpoint to use." ) model_checkpoint1 = 'Diezu/viedumrc' question_answerer = pipeline("question-answering", model=model_checkpoint1) st.sidebar.markdown( """ Using model: Diezu/viedumrc. """, unsafe_allow_html=True, ) context_sidebar = st.sidebar.text_area( "Context", "", help="Enter the context that contains information for answering questions.", height=200, placeholder="Provide context for your question...", ) # # Load the tokenizer and model with error handling # try: # tokenizer = AutoTokenizer.from_pretrained(model_checkpoint) # model = AutoModelForQuestionAnswering.from_pretrained(model_checkpoint) # question_answerer = pipeline("question-answering", model=model, tokenizer=tokenizer) # except Exception as e: # st.error(f"Failed to load model or tokenizer: {e}", icon="🚨") # st.stop() # Main application st.markdown( """

Provide Context and Question

""", unsafe_allow_html=True, ) # Input: question question = st.text_input( "Question", "", help="Write the question you want to ask about the provided context.", placeholder="What is your question?", ) # Button to get answer if st.button("Get Answer"): if context_sidebar.strip() == "" or question.strip() == "": st.warning("Please provide both context and a question!", icon="⚠️") else: try: # Using context from the sidebar and question from the main section result = question_answerer(question=question, context=context_sidebar) st.success("Answer Found!", icon="✅") st.markdown( f"""
Answer: {result['answer']}
""", unsafe_allow_html=True, ) except Exception as e: st.error(f"Error while processing: {e}", icon="🚨") # Footer with custom style st.markdown( """
""", unsafe_allow_html=True, ) # import streamlit as st # from transformers import pipeline # st.title('Question Answering') # model_checkpoint = 'Diezu/dieumrc' # question_answerer = pipeline("question-answering", model=model_checkpoint) # context = st.text_area('CONTEXT') # question = st.text_input('QUESTION') # if st.button('ANSWER'): # i=question_answerer(question,context) # #st.write(i['answer']) # st.markdown(i['answer']) # #st.write('

i['answer']

')