Skip to content

Commit

Permalink
doc creation done
Browse files Browse the repository at this point in the history
  • Loading branch information
spike-spiegel-21 committed Apr 28, 2024
1 parent 2917120 commit e4fa49d
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
**/__pycache__/
Binary file removed api/legal_notice.docx
Binary file not shown.
Binary file removed api/new.docx
Binary file not shown.
21 changes: 7 additions & 14 deletions document_maker/document_maker.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
# from docx import Document
# import os
from docx import Document
from open_ai.openai_api import OpenAI

#document_path = os.path.join('.', 'legal_notice_template.docx')
#path_of_template = './legal_notice_template.docx'
#dev-> TODO: What if any point is incomplete?
import sys
class DocumentMaker:
#initialize path
def __init__(self, path):
#self.path = path
self.document = Document(path)
#change after database allotment
self.new_path = 'legal_notice.docx'
self.new_path = 'legal_notice_new.docx'

#save function
def save(self):
self.document.save(self.new_path)


def replace_common(self, search_text, replace_text):
for paragraph in self.document.paragraphs:
for run in paragraph.runs:

if search_text in run.text:
if search_text == "defect_des":
run.text = OpenAI().get_response(replace_text)
# run.text = OpenAI().get_response(replace_text)
run.text = "gg"
break
if search_text == "name_of_company":
run.text = replace_text.upper()
# run.text = replace_text.upper()
run.text = "gg"
break
run.text = replace_text
self.save()
Expand Down
Binary file removed document_maker/legal_notice_template.docx
Binary file not shown.
Binary file removed document_maker/test.docx
Binary file not shown.
Binary file added legal_notice_new.docx
Binary file not shown.
Binary file added legal_notice_template.docx
Binary file not shown.
25 changes: 10 additions & 15 deletions api/api.py → main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
from fastapi.responses import FileResponse

from document_maker.document_maker import DocumentMaker
path_of_template = "../document_maker/legal_notice_template.docx"
path_of_template = "legal_notice_template.docx"

def get_document_maker():
return DocumentMaker(path_of_template)


app = FastAPI()

# Allow all origins, methods, and headers. Adjust these settings based on your needs.
Expand All @@ -32,18 +31,6 @@ def get_document_maker():
async def read_root():
return {"Hello": "World"}

# {
# "name_of_company":"amazon",
# "name_of_entity":"Mr. Jeff Bezos",
# "address_of_entity":"6th & 7th Floor, Ambience Corporate Office Tower-II, Ambience Tower, Ambience Island, Sector 24, Gurugram, Haryana 122002",
# "date_of_rec":"16/02/2024",
# "amount_of_rec":"5000",
# "defect_des": "I have taken the cultfit play pass member ship which charged me around 10000 rs for 3 months. In this memebership I was allowed to play in any of their play centers. At the time of memebership I was using their service for sector 23 which have 3 facaliteis of sports (incl. Badminton, Table Tennis and Lawn Tennis) After having there for around 3 weeks they are shutting down this place due to some reason. When I sad them for the refund the remaining amount they said you can use the service that is available in othr centere which is very far from my current residence. They said that the amound is not refundable.",
# "amount_to_get":"5000",
# "contact_of_user":"+91-888-888-xxxx",
# "email_of_user":"[email protected]"
# }


#post route for fetching form data
@app.post("/process_json_data")
Expand All @@ -60,4 +47,12 @@ def process_json_data(json_data: dict = Body(...), document_maker: DocumentMaker
document_maker.replace_common("email_of_user",json_data.get("email_of_user"))


return FileResponse('./legal_notice.docx', filename='legal_notice.docx')
return FileResponse('./legal_notice_new.docx', filename='legal_notice.docx')








5 changes: 0 additions & 5 deletions open_ai/openai_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
load_dotenv()
client = OpenAI()


# A class to handle the openai api
class OpenAI:

#additional code
def __init__(self):
self.api_key = os.getenv("OPENAI_API_KEY")

Expand All @@ -24,5 +20,4 @@ def get_response(self, message):
)
return str(completion.choices[0].message.content)


#print(type(OpenAI().get_response("I have taken the cultfit play pass member ship which charged me around 10000 rs for 3 months. In this memebership I was allowed to play in any of their play centers. At the time of memebership I was using their service for sector 23 which have 3 facaliteis of sports (incl. Badminton, Table Tennis and Lawn Tennis) After having there for around 3 weeks they are shutting down this place due to some reason. When I sad them for the refund the remaining amount they said you can use the service that is available in othr centere which is very far from my current residence. They said that the amound is not refundable.")))
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1. Check for the supported docx format before running
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fastapi
openai
python-dotenv
python-docx
uvicorn[standard]

0 comments on commit e4fa49d

Please sign in to comment.