typesdigital commited on
Commit
70b6cd9
·
verified ·
1 Parent(s): 739cfa8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -1,23 +1,19 @@
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Load pre-trained question-answering model from Hugging Face Hub
5
- qa_pipe = pipeline("question-answering")
6
 
7
- # Function to process user query and return answer
8
- def answer_question(query):
9
- context = "This is a large corpus of text used for training the model (replace with your actual context if needed)" # Replace with relevant context
10
- qa_result = qa_pipe(question=query, context=context)
11
- return qa_result["answer"]
12
 
13
- def main():
14
- st.title("Question & Answer Chatbot (Limited Functionality)")
15
- st.write("This chatbot uses a pre-trained model from Hugging Face Hub. It might not have the same capabilities as a large language model.")
16
 
17
- user_query = st.text_input("Ask your question:")
18
- if user_query:
19
- answer = answer_question(user_query)
20
- st.write(f"Answer: {answer}")
21
 
22
- if __name__ == "__main__":
23
- main()
 
 
1
+ # app.py
2
  import streamlit as st
3
  from transformers import pipeline
4
 
5
+ # Load sentiment analysis pipeline
6
+ classifier = pipeline("sentiment-analysis")
7
 
8
+ def analyze_sentiment(text):
9
+ """Analyzes the sentiment of a given text."""
10
+ result = classifier(text)
11
+ return result[0]['label'], result[0]['score']
 
12
 
13
+ st.title("Sentiment Analysis App")
 
 
14
 
15
+ text = st.text_area("Enter your text here:")
 
 
 
16
 
17
+ if st.button("Analyze"):
18
+ label, score = analyze_sentiment(text)
19
+ st.success(f"Sentiment: {label}, Score: {score}")