rohitashva commited on
Commit
90cc9e6
·
verified ·
1 Parent(s): 69eddeb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Set up the title and description of the app
5
+ st.title("My LLM Model: Dementia Knowledge Assistant")
6
+ st.markdown("""
7
+ This app uses a fine-tuned **Large Language Model (LLM)** to answer questions about dementia.
8
+ Simply input your query, and the model will provide contextually relevant answers!
9
+ """)
10
+
11
+ # Load the model
12
+ @st.cache_resource
13
+ def load_qa_pipeline():
14
+ model_name = "rohitashva/dementia--chatbot-llm-model" # Replace with your Hugging Face model repo name
15
+ qa_pipeline = pipeline("text-generation", model=model_name)
16
+ return qa_pipeline
17
+
18
+ qa_pipeline = load_qa_pipeline()
19
+
20
+ # Input field for user query
21
+ st.header("Ask a Question")
22
+ question = st.text_input("Enter your question about dementia (e.g., 'What are the symptoms of early-stage dementia?'):")
23
+
24
+ # Context input for retrieval
25
+ st.text_area(
26
+ "Provide additional context (optional):",
27
+ placeholder="Include any relevant context about dementia here to get better results.",
28
+ key="context"
29
+ )
30
+
31
+ if st.button("Get Answer"):
32
+ if not question:
33
+ st.error("Please enter a question!")
34
+ else:
35
+ # Call the QA pipeline
36
+ with st.spinner("Generating response..."):
37
+ result = qa_pipeline({
38
+ "question": question,
39
+ "context": st.session_state.context
40
+ })
41
+ answer = result.get("answer", "I don't know.")
42
+ confidence = result.get("score", 0.0)
43
+
44
+ # Display the result
45
+ st.subheader("Answer")
46
+ st.write(answer)
47
+
48
+ st.subheader("Confidence Score")
49
+ st.write(f"{confidence:.2f}")
50
+
51
+ # Footer
52
+ st.markdown("---")
53
+ st.markdown("Deployed on **Hugging Face Spaces** using [Streamlit](https://streamlit.io/).")