mugiwarafx commited on
Commit
7e6d5ed
1 Parent(s): e5d1547

remove logging

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -1,13 +1,8 @@
1
- import logging
2
- from fastapi import FastAPI, HTTPException
3
  from pydantic import BaseModel
4
  from bs4 import BeautifulSoup
5
  from typing import List, Dict
6
 
7
- # Configure logging
8
- logging.basicConfig(level=logging.DEBUG)
9
- logger = logging.getLogger(__name__)
10
-
11
  app = FastAPI()
12
 
13
  all_html_tags = {
@@ -32,7 +27,6 @@ class HTMLOutput(BaseModel):
32
 
33
 
34
  def extract_html_tags(html_code: str) -> Dict[str, List[str]]:
35
- logger.debug(f"Extracting HTML tags from code: {html_code}")
36
  soup = BeautifulSoup(html_code, "html.parser")
37
  tags_used = {tag.name for tag in soup.find_all()}
38
  tags_not_used = all_html_tags - tags_used
@@ -46,16 +40,22 @@ def extract_html_tags(html_code: str) -> Dict[str, List[str]]:
46
  async def extract_tags(input: HTMLInput):
47
  try:
48
  result = extract_html_tags(input.html_code)
49
- logger.debug(f"Extraction result: {result}")
50
  return HTMLOutput(**result)
51
  except Exception as e:
52
- logger.error(f"Error during extraction: {e}")
53
  raise HTTPException(status_code=500, detail=str(e))
54
 
55
- # Add a simple root endpoint to confirm the server is running
 
 
 
 
 
 
 
 
 
56
 
57
 
58
  @app.get("/")
59
  async def root():
60
- logger.debug("Root endpoint called")
61
  return {"message": "FastAPI application is running"}
 
1
+ from fastapi import FastAPI, HTTPException, Request
 
2
  from pydantic import BaseModel
3
  from bs4 import BeautifulSoup
4
  from typing import List, Dict
5
 
 
 
 
 
6
  app = FastAPI()
7
 
8
  all_html_tags = {
 
27
 
28
 
29
  def extract_html_tags(html_code: str) -> Dict[str, List[str]]:
 
30
  soup = BeautifulSoup(html_code, "html.parser")
31
  tags_used = {tag.name for tag in soup.find_all()}
32
  tags_not_used = all_html_tags - tags_used
 
40
  async def extract_tags(input: HTMLInput):
41
  try:
42
  result = extract_html_tags(input.html_code)
 
43
  return HTMLOutput(**result)
44
  except Exception as e:
 
45
  raise HTTPException(status_code=500, detail=str(e))
46
 
47
+
48
+ @app.post("/extract_tags_raw", response_model=HTMLOutput)
49
+ async def extract_tags_raw(request: Request):
50
+ try:
51
+ html_code = await request.body()
52
+ html_code = html_code.decode("utf-8")
53
+ result = extract_html_tags(html_code)
54
+ return HTMLOutput(**result)
55
+ except Exception as e:
56
+ raise HTTPException(status_code=500, detail=str(e))
57
 
58
 
59
  @app.get("/")
60
  async def root():
 
61
  return {"message": "FastAPI application is running"}