File size: 1,924 Bytes
36b4a9d
24af938
36b4a9d
24af938
 
36b4a9d
24af938
 
 
36b4a9d
 
24af938
36b4a9d
24af938
36b4a9d
24af938
 
36b4a9d
 
24af938
 
f431d57
24af938
 
6de3eae
 
36b4a9d
24af938
 
 
 
 
 
 
 
36b4a9d
 
 
24af938
36b4a9d
24af938
36b4a9d
24af938
36b4a9d
58ee331
 
 
 
24af938
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
import streamlit as st
from transformers import BartTokenizer, BartForConditionalGeneration

# Replace with your Hugging Face model repository path for QnA
model_repo_path_qna = 'ASaboor/Bart_Therapy'

# Load the model and tokenizer for QnA
model_qna = BartForConditionalGeneration.from_pretrained(model_repo_path_qna)
tokenizer_qna = BartTokenizer.from_pretrained(model_repo_path_qna)

# Streamlit app layout
st.set_page_config(page_title="QnA App", page_icon=":memo:", layout="wide")

st.title("Question and Answer App")
st.write("""
    This app uses a fine-tuned BART model to answer questions.
    Enter your question below and click "Get Answer" to see the result.
""")

# User input for QnA
question_input = st.text_input("Enter question", placeholder="Type your question here...")

# Generate the answer
if st.button("Get Answer"):
    if question_input:
        with st.spinner("Generating answer..."):
            try:
                # Tokenize input
                inputs = tokenizer_qna(question_input, return_tensors='pt', max_length=512, truncation=True)
                
                # Generate answer
                outputs = model_qna.generate(input_ids=inputs['input_ids'], attention_mask=inputs['attention_mask'], max_length=150, num_beams=5, early_stopping=True)
                
                # Decode the answer
                answer = tokenizer_qna.decode(outputs[0], skip_special_tokens=True)
                
                # Display answer
                st.subheader("Answer")
                st.write(answer)
            except Exception as e:
                st.error(f"An error occurred during QnA: {e}")
    else:
        st.warning("Please enter a question for QnA.")

# Optional: Add a footer or additional information
st.markdown("""
    ---
    Made with ❤️ using [Streamlit](https://streamlit.io) and [Hugging Face Transformers](https://huggingface.co/transformers/).
""")