[Tutor] Flask-Python Beginner

Baptista Albert ireneprajay at gmail.com
Sun Oct 25 20:26:28 EDT 2020


Hi,

I doing a small project by myself on building a resume parser. I wrote the
Python script and it works just fine with the document path hardcoded in it.

I am not trying to convert into an API using flask and am facing a lot of
issues,

resumeparser2.py:

import os
import docx2txt
import spacy
from spacy.matcher import Matcher
from pyresparser import ResumeParser
import pandas as pd
import re
from flask import Flask, request
from flask_restful import Resource, Api
import nltk
from nltk.corpus import stopwords
STOPWORDS = set(stopwords.words('english'))

app = Flask(__name__)
api= Api(app)
#@app.route('/resumeparser2', methods=['GET'])

#extracting data from docx

class resparse:

    def resumeparser2(self) :
        doc_path=(r"C:\U
sers\Ajay Charles\Downloads\Baptista Albert - BA resume.docx")
        temp = docx2txt.process(doc_path)
        text = [line.replace('\t', ' ') for line in temp.split('\n') if
 line]
        return_text= ' '.join(text)
        nlp = spacy.load('en_core_web_sm')
        nlp_text = nlp(return_text)
        for chunk in nlp_text.noun_chunks:
            word_chunk = (chunk.text)
        matcher = Matcher(nlp.vocab)

    #extracting Full name
        pattern = [{'POS':'PROPN'},{'POS':"PROPN"},{'POS':'PROPN'},{'POS':
'PROPN'}]
        matcher.add('NAME',None, pattern)
        matches = matcher(nlp_text)
        for match_id, start, end in matches:
            span = nlp_text[start:end]
            return(span)
            break

        phone = re.findall(re.compile(r'\d{3}[-\.\s]??\d{3}[-\.\s]??\d{4}|\(
\d{3}\)\s*\d{3}[-\.\s]??\d{4}|\d{3}[-\.\s]??\d{4}'), return_text)
        for ph_num in phone:
            return(ph_num)

        email1 = re.findall(r"([^@|\s]+@[^@]+\.[^@|\s]+)" , return_text)
        for email in email1:
            return (email)

        address = re.findall(re.compile(r'Alabama|AL|Alaska|AK|Arizona|AZ|
Arkansas|AR|California|CA|Colorado|CO|Connecticut|CT|Delaware|DE|Florida|FL|
Georgia|GA|Hawaii|HI|Idaho|ID|Illinois|IL|Indiana|IN|Iowa|IA|Kansas|KS|
Kentucky|KY|Louisiana|LA|Maine|ME|Maryland|MD|Massachusetts|MA|Michigan|MI|
Minnesota|MN|Mississippi|MS|Missouri|MO|Montana|MT|Nebraska|NE|Nevada|NV|
New Hampshire|NH|New Jersey|NJ|New Mexico|NM|New York|NY|North Carolina|NC|
North Dakota|ND|Ohio|OH|Oklahoma|OK|Oregon|OR|Pennsylvania|PA|Rhode Island|
RI|South Carolina|SC|South Dakota|SD|Tennessee|TN|Texas|TX|Utah|UT|Vermont|
VT|Virginia|VA|Washington|WA|West Virginia|WV|Wisconsin|WI|Wyoming|WY'
),return_text)
        for addr in address:
            return(addr)
            break

#resumeparser2()


api.add_resource(resparse,'/resumeparser2')

#def get_tasks():
#    return resumeparser2()

if __name__ == '__main__':
    app.run()





Errors:

PS C:\Users\Ajay Charles\Downloads\Python\PythonProjects> &
C:/Python38/python.exe "c:/Users/Ajay
Charles/Downloads/Python/PythonProjects/resumeparser2.py"
Traceback (most recent call last):
  File "c:/Users/Ajay
Charles/Downloads/Python/PythonProjects/resumeparser2.py", line 58, in
<module>
    api.add_resource(resparse,'/resumeparser2')
  File "C:\Users\Ajay
Charles\AppData\Roaming\Python\Python38\site-packages\flask_restful\__init__.py",
line 392, in add_resource
    self._register_view(self.app, resource, *urls, **kwargs)
  File "C:\Users\Ajay
Charles\AppData\Roaming\Python\Python38\site-packages\flask_restful\__init__.py",
line 432, in _register_view
    resource_func = self.output(resource.as_view(endpoint,
*resource_class_args,
AttributeError: type object 'resparse' has no attribute 'as_view'

Please do let me know where I am going wrong.
-- 
Baptista Albert


More information about the Tutor mailing list