Spaces:
Runtime error
Runtime error
Commit ·
9f8fe28
1
Parent(s): 1455995
Add CORS Fix
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- app.py +58 -4
__pycache__/app.cpython-311.pyc
ADDED
|
Binary file (4.77 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,16 +1,36 @@
|
|
| 1 |
-
import requests
|
| 2 |
import json
|
| 3 |
-
import pdfplumber
|
| 4 |
-
import pandas as pd
|
| 5 |
import time
|
| 6 |
-
from cnocr import CnOcr
|
| 7 |
# from sentence_transformers import SentenceTransformer, models, util
|
|
|
|
| 8 |
|
| 9 |
from fastapi import FastAPI, UploadFile, File
|
| 10 |
|
| 11 |
from fastapi.responses import HTMLResponse
|
|
|
|
|
|
|
|
|
|
| 12 |
app = FastAPI()
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
@app.get("/")
|
| 15 |
def home():
|
| 16 |
html_content = open('index.html').read()
|
|
@@ -56,3 +76,37 @@ async def up_file(file: UploadFile = File(...)):
|
|
| 56 |
print(doc_text_list)
|
| 57 |
return doc_text_list
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import requests
|
| 2 |
import json
|
| 3 |
+
# import pdfplumber
|
| 4 |
+
# import pandas as pd
|
| 5 |
import time
|
| 6 |
+
# from cnocr import CnOcr
|
| 7 |
# from sentence_transformers import SentenceTransformer, models, util
|
| 8 |
+
import mysql.connector
|
| 9 |
|
| 10 |
from fastapi import FastAPI, UploadFile, File
|
| 11 |
|
| 12 |
from fastapi.responses import HTMLResponse
|
| 13 |
+
|
| 14 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 15 |
+
|
| 16 |
app = FastAPI()
|
| 17 |
|
| 18 |
+
|
| 19 |
+
origins = [
|
| 20 |
+
"http://localhost",
|
| 21 |
+
"http://localhost:8080",
|
| 22 |
+
"http://localhost:3000",
|
| 23 |
+
"https://invoice-pdf-xi.vercel.app"
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
app.add_middleware(
|
| 27 |
+
CORSMiddleware,
|
| 28 |
+
allow_origins=origins,
|
| 29 |
+
allow_credentials=True,
|
| 30 |
+
allow_methods=["*"],
|
| 31 |
+
allow_headers=["*"],
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
@app.get("/")
|
| 35 |
def home():
|
| 36 |
html_content = open('index.html').read()
|
|
|
|
| 76 |
print(doc_text_list)
|
| 77 |
return doc_text_list
|
| 78 |
|
| 79 |
+
# @app.get("/{provider_id}")
|
| 80 |
+
# def get_provider(provider_id):
|
| 81 |
+
conn = mysql.connector.connect(
|
| 82 |
+
host="localhost",
|
| 83 |
+
user="root",
|
| 84 |
+
passwd="1234",
|
| 85 |
+
database="cg_app",
|
| 86 |
+
auth_plugin='mysql_native_password'
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
if conn.is_connected():
|
| 90 |
+
print('Connected to MySQL database')
|
| 91 |
+
|
| 92 |
+
cursor = conn.cursor()
|
| 93 |
+
|
| 94 |
+
query = f"SELECT * FROM email_automation_invoice_provider_profile_updated WHERE provider_id={provider_id}"
|
| 95 |
+
cursor.execute(query)
|
| 96 |
+
|
| 97 |
+
# Get column names from cursor description
|
| 98 |
+
column_names = [col[0] for col in cursor.description]
|
| 99 |
+
|
| 100 |
+
# Create list of dictionaries representing rows
|
| 101 |
+
rows = []
|
| 102 |
+
for row in cursor.fetchall():
|
| 103 |
+
row_dict = {}
|
| 104 |
+
for i, value in enumerate(row):
|
| 105 |
+
row_dict[column_names[i]] = value
|
| 106 |
+
rows.append(row_dict)
|
| 107 |
+
|
| 108 |
+
cursor.close()
|
| 109 |
+
conn.close()
|
| 110 |
+
|
| 111 |
+
# Return result as JSON response
|
| 112 |
+
return rows
|