pratikshahp commited on
Commit
4f36d7f
·
verified ·
1 Parent(s): 8bc90af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -13
app.py CHANGED
@@ -2,7 +2,6 @@ import streamlit as st
2
  import requests
3
  from bs4 import BeautifulSoup
4
  from transformers import pipeline
5
- from langchain import LanguageModelChain, PromptTemplate, QAPrompt
6
 
7
  # Function to scrape text content from a URL
8
  def scrape_text_from_url(url):
@@ -24,15 +23,6 @@ def scrape_text_from_url(url):
24
  def load_qa_model():
25
  return pipeline('question-answering')
26
 
27
- # Create LangChain pipeline
28
- def create_langchain_pipeline(model):
29
- template = PromptTemplate(
30
- input_variables=["context", "question"],
31
- template="Context: {context}\nQuestion: {question}\nAnswer:"
32
- )
33
- qa_prompt = QAPrompt(template=template)
34
- return LanguageModelChain(llm=model, prompt=qa_prompt)
35
-
36
  # Streamlit app
37
  st.title("Question Answering from URL")
38
  url = st.text_input("Enter the URL of the webpage:")
@@ -41,9 +31,8 @@ if url:
41
  if text:
42
  st.write("Webpage content successfully retrieved!")
43
  qa_model = load_qa_model()
44
- langchain_pipeline = create_langchain_pipeline(qa_model)
45
 
46
  question = st.text_input("Enter your question:")
47
  if question:
48
- answer = langchain_pipeline.run(context=text, question=question)
49
- st.write("Answer:", answer)
 
2
  import requests
3
  from bs4 import BeautifulSoup
4
  from transformers import pipeline
 
5
 
6
  # Function to scrape text content from a URL
7
  def scrape_text_from_url(url):
 
23
  def load_qa_model():
24
  return pipeline('question-answering')
25
 
 
 
 
 
 
 
 
 
 
26
  # Streamlit app
27
  st.title("Question Answering from URL")
28
  url = st.text_input("Enter the URL of the webpage:")
 
31
  if text:
32
  st.write("Webpage content successfully retrieved!")
33
  qa_model = load_qa_model()
 
34
 
35
  question = st.text_input("Enter your question:")
36
  if question:
37
+ result = qa_model(question=question, context=text)
38
+ st.write("Answer:", result['answer'])