main.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import uvicorn
  2. from fastapi import FastAPI
  3. from pydantic import BaseModel
  4. from tool.pdf2md import pdf2ai
  5. from utils import dmQuery
  6. from utils.shellUtil import execute_command_on_linux
  7. from utils.text_to_html import save_html_to_file
  8. app = FastAPI() # 创建API实例
  9. @app.get("/")
  10. async def root():
  11. return {"message": "Hello World"}
  12. # 将数据模型定义为继承BaseModel的类
  13. class Item(BaseModel):
  14. sql: str
  15. class Pdf2md(BaseModel):
  16. pdfUrl: str
  17. prompt: str
  18. pageNum: int
  19. class Saved2text(BaseModel):
  20. htmlContent: str
  21. fileName: str
  22. @app.put("/exsql")
  23. async def create_item( item: Item, q: str = None):
  24. result = {**item.dict()}
  25. results = dmQuery.execute_query(item.sql)
  26. return results
  27. @app.put("/exshell")
  28. async def create_item( item: Item, q: str = None):
  29. # 配置 Linux 服务器信息
  30. host = '119.29.146.254'
  31. port = 22
  32. username = 'root'
  33. password = 'zrd1236987!'
  34. # 要执行的命令
  35. result = execute_command_on_linux(host, port, username, password, item.sql)
  36. return result
  37. @app.put("/pdf2md")
  38. async def pdf2md(item: Pdf2md, q: str = None):
  39. pdf_url = 'http://42.194.163.46:9007/ywd/%E6%89%AB%E6%8F%8F%E5%85%A8%E8%83%BD%E7%8E%8B%202025-03-20%2021.38.pdf'
  40. prompt = "提取有效信息,只输出图片有效信息无效信息不用。"
  41. result = pdf2ai(item.pdfUrl, item.prompt, item.pageNum)
  42. return result
  43. @app.put("/pdf2md")
  44. async def saved2text(item: Saved2text, q: str = None):
  45. pdf_url = 'http://42.194.163.46:9007/ywd/%E6%89%AB%E6%8F%8F%E5%85%A8%E8%83%BD%E7%8E%8B%202025-03-20%2021.38.pdf'
  46. prompt = "提取有效信息,只输出图片有效信息无效信息不用。"
  47. result = save_html_to_file(item.htmlContent, item.fileName)
  48. return result
  49. if __name__ == "__main__":
  50. uvicorn.run(app, host="0.0.0.0", port=29015, timeout_keep_alive=600)