mirror of
https://github.com/bvanroll/question_answer.git
synced 2025-08-28 11:32:48 +00:00
initial commit
This commit is contained in:
1
data.txt
Normal file
1
data.txt
Normal file
@@ -0,0 +1 @@
|
||||
The Amazon rainforest (Portuguese: Floresta Amazônica or Amazônia; Spanish: Selva Amazónica, Amazonía or usually Amazonia; French: Forêt amazonienne; Dutch: Amazoneregenwoud), also known in English as Amazonia or the Amazon Jungle, is a moist broadleaf forest that covers most of the Amazon basin of South America. This basin encompasses 7,000,000 square kilometres (2,700,000 sq mi), of which 5,500,000 square kilometres (2,100,000 sq mi) are covered by the rainforest. This region includes territory belonging to nine nations. The majority of the forest is contained within Brazil, with 60% of the rainforest, followed by Peru with 13%, Colombia with 10%, and with minor amounts in Venezuela, Ecuador, Bolivia, Guyana, Suriname and French Guiana. States or departments in four nations contain "Amazonas" in their names. The Amazon represents over half of the planet's remaining rainforests, and comprises the largest and most biodiverse tract of tropical rainforest in the world, with an estimated 390 billion individual trees divided into 16,000 species.
|
50
main.py
Normal file
50
main.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import os
|
||||
import cherrypy
|
||||
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
||||
model_name = "deepset/roberta-base-squad2"
|
||||
|
||||
path = os.path.abspath(os.path.dirname(__file__))
|
||||
config = {
|
||||
'global' : {
|
||||
'server.socket_host' : '127.0.0.1',
|
||||
'server.socket_port' : 8080,
|
||||
'server.thread_pool' : 8,
|
||||
},
|
||||
}
|
||||
|
||||
class Root(object):
|
||||
|
||||
|
||||
|
||||
def answer_question(self, question, context):
|
||||
question_answerer = pipeline('question-answering', model=model_name, tokenizer=model_name)
|
||||
answer = question_answerer({'question': question, 'context': context})
|
||||
print(answer)
|
||||
return answer["answer"]
|
||||
|
||||
@cherrypy.expose
|
||||
def index(self, *args, **kwargs):
|
||||
answer = ""
|
||||
|
||||
with open('data.txt') as f:
|
||||
context = f.read()
|
||||
f.close()
|
||||
|
||||
if cherrypy.request.params.get('question'):
|
||||
question_answerer = pipeline('question-answering', model=model_name, tokenizer=model_name)
|
||||
temp = question_answerer({'question': cherrypy.request.params.get('question'), 'context': context})
|
||||
answer = "<h1>answer</h1><p>{}</p>".format(temp["answer"])
|
||||
|
||||
return "<html><head><title>reinout project 1</title></head><body><h1>question</h1><form method=\"POST\" action=\"index\"><input type=\"text\" name=\"question\" size=\"50\"/><button type=\"submit\">send!</button></form>{}</body></html>".format(answer)
|
||||
|
||||
@cherrypy.expose
|
||||
def question(self, *args,**kwargs):
|
||||
with open('data.txt') as f:
|
||||
alles = f.read()
|
||||
f.close()
|
||||
string=self.answer_question(cherrypy.request.params.get('the_link'), alles)
|
||||
return string
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cherrypy.quickstart(Root(), '/', config)
|
15
readme.md
Normal file
15
readme.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# stappen
|
||||
|
||||
## requirements:
|
||||
python 3.9
|
||||
pip
|
||||
|
||||
## installation
|
||||
pip install -r requirements.txt
|
||||
python main.py
|
||||
|
||||
## access application
|
||||
localhost:8080 in browser
|
||||
|
||||
## data.txt
|
||||
fill data.txt with necessary context for question to be answered.
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
cherrypy=18.8.0
|
||||
tensorflow=2.10.1
|
||||
transformers=4.24.0
|
Reference in New Issue
Block a user