PercivalFletcher commited on
Commit
942a690
·
verified ·
1 Parent(s): 8ae65d4

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -0
  2. main.py +66 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dockerfile
2
+
3
+ # Use an official Python runtime as a parent image
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+
9
+ WORKDIR /app
10
+
11
+ COPY --chown=user ./requirements.txt requirements.txt
12
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
13
+
14
+ COPY --chown=user . /app
15
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # main.py
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel, Field, HttpUrl
4
+ from typing import List
5
+
6
+ # -- 1. Define Pydantic Models for Data Validation --
7
+
8
+ # This model defines the structure of the incoming request JSON
9
+ class RequestPacket(BaseModel):
10
+ text: str
11
+ url: HttpUrl # Pydantic validates this is a valid URL
12
+ image: str # Expecting a base64 encoded string
13
+
14
+ # These models define the structure of the outgoing response JSON
15
+ class Analysis(BaseModel):
16
+ isMisinformation: bool
17
+ reasoning: str
18
+ confidenceScore: float = Field(
19
+ ...,
20
+ ge=0, # Must be greater than or equal to 0
21
+ le=1 # Must be less than or equal to 1
22
+ )
23
+
24
+ class Source(BaseModel):
25
+ name: str
26
+ description: str
27
+
28
+ class ResponsePacket(BaseModel):
29
+ summary: str
30
+ analysis: Analysis
31
+ sources: List[Source]
32
+
33
+ # -- 2. Create the FastAPI Application --
34
+ app = FastAPI(
35
+ title="Backend Checker API",
36
+ description="A mock API to validate requests and send simulated responses."
37
+ )
38
+
39
+ # -- 3. Define the API Endpoint --
40
+ @app.post("/check", response_model=ResponsePacket)
41
+ async def check_request_format(request: RequestPacket):
42
+ """
43
+ This endpoint receives a request packet, validates its structure,
44
+ and returns a mock analysis response.
45
+ """
46
+ # For your debugging: print a confirmation to the server console
47
+ print("✅ Request received and successfully validated!")
48
+ print(f"Received URL: {request.url}")
49
+ print(f"Text length: {len(request.text)}")
50
+ print(f"Image string starts with: {request.image[:30]}...")
51
+
52
+ # -- 4. Create and Return the Mock Response --
53
+ mock_response = ResponsePacket(
54
+ summary="This is a simulated summary based on the provided text. The analysis suggests the content requires further verification due to conflicting reports from primary sources.",
55
+ analysis=Analysis(
56
+ isMisinformation=True,
57
+ reasoning="The claim contradicts established facts from reputable news organizations and scientific consensus. The provided image appears to be digitally altered.",
58
+ confidenceScore=0.88
59
+ ),
60
+ sources=[
61
+ Source(name="Verified Source A", description="Provides data that conflicts with the user's text."),
62
+ Source(name="FactCheck Organization B", description="Previously debunked a similar claim.")
63
+ ]
64
+ )
65
+
66
+ return mock_response
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # requirements.txt
2
+ fastapi
3
+ uvicorn[standard]
4
+ pydantic