TANVEERMAKHDOOM commited on
Commit
06fc207
·
verified ·
1 Parent(s): b38fe5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -1,23 +1,25 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Title
5
- st.title("🤖 AI Chatbot - Hugging Face")
6
 
7
- # Initialize chatbot model
8
  @st.cache_resource
9
- def load_chatbot():
10
- return pipeline("text-generation", model="microsoft/DialoGPT-medium")
11
 
12
- chatbot = load_chatbot()
13
 
14
- # User input
15
- user_input = st.text_input("You:", "")
 
16
 
17
- # If user types something
18
- if user_input:
19
- # Generate response
20
- with st.spinner("Chatbot is thinking..."):
21
- response = chatbot(user_input, max_length=100, do_sample=True, pad_token_id=50256)
22
- bot_reply = response[0]['generated_text'].split(user_input)[-1].strip()
23
- st.markdown(f"**Bot:** {bot_reply}")
 
 
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ st.title("❓ AI Question Answering Bot")
 
5
 
 
6
  @st.cache_resource
7
+ def load_qa():
8
+ return pipeline("question-answering", model="deepset/roberta-base-squad2")
9
 
10
+ qa = load_qa()
11
 
12
+ # Set a static context or let user provide it
13
+ context = st.text_area("📄 Paste your reference text (context):",
14
+ "The QA QC Electrical Inspector ensures the quality of installations, performs inspection and testing, and checks documentation in power and oil & gas projects.")
15
 
16
+ question = st.text_input("❓ Your question:")
17
+
18
+ if question:
19
+ try:
20
+ with st.spinner("Thinking..."):
21
+ answer = qa(question=question, context=context)
22
+ st.markdown(f"**Answer:** {answer['answer']}")
23
+ except Exception as e:
24
+ st.error("Something went wrong.")
25
+ st.exception(e)