Spaces:
Runtime error
Runtime error
Commit ·
01a0c13
1
Parent(s): f4d3d89
Add Gradio changes and email data CSV
Browse files- app.py +33 -1
- combined_emails_with_natural_pii.csv +3 -0
- requirements.txt +4 -1
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
# filepath: /workspaces/internship1/app.py
|
| 2 |
import uvicorn
|
| 3 |
import os
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Import the FastAPI app instance from api.py
|
| 6 |
# Ensure the FastAPI instance in api.py is named 'app'
|
|
@@ -14,7 +16,36 @@ except Exception as e:
|
|
| 14 |
print(f"An unexpected error occurred during import: {e}")
|
| 15 |
app = None
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
|
|
|
| 18 |
if __name__ == "__main__":
|
| 19 |
if app:
|
| 20 |
# Get port from environment variable PORT, default to 8000
|
|
@@ -24,4 +55,5 @@ if __name__ == "__main__":
|
|
| 24 |
print(f"Starting Uvicorn server on host 0.0.0.0, port {port}")
|
| 25 |
uvicorn.run(app, host="0.0.0.0", port=port)
|
| 26 |
else:
|
| 27 |
-
print("Could not start server because the FastAPI app instance was not loaded.")
|
|
|
|
|
|
| 1 |
# filepath: /workspaces/internship1/app.py
|
| 2 |
import uvicorn
|
| 3 |
import os
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import json
|
| 6 |
|
| 7 |
# Import the FastAPI app instance from api.py
|
| 8 |
# Ensure the FastAPI instance in api.py is named 'app'
|
|
|
|
| 16 |
print(f"An unexpected error occurred during import: {e}")
|
| 17 |
app = None
|
| 18 |
|
| 19 |
+
# Assumption: 'process_email_request' is the function that takes email text
|
| 20 |
+
# and returns the dictionary with keys like 'input_email_body', 'list_of_masked_entities', etc.
|
| 21 |
+
# Adjust the import based on where this function is defined (e.g., utils.py, api.py)
|
| 22 |
+
try:
|
| 23 |
+
from utils import process_email_request
|
| 24 |
+
print("Successfully imported process_email_request from utils.")
|
| 25 |
+
except ImportError:
|
| 26 |
+
print("Could not import process_email_request from utils. Trying from api...")
|
| 27 |
+
try:
|
| 28 |
+
# If the logic is maybe within api.py but callable
|
| 29 |
+
from api import process_email_request # Adjust if the function name is different
|
| 30 |
+
print("Successfully imported process_email_request from api.")
|
| 31 |
+
except ImportError:
|
| 32 |
+
print("ERROR: Could not find the core processing function 'process_email_request'.")
|
| 33 |
+
print("Please ensure it's defined and importable from utils.py or api.py")
|
| 34 |
+
# Define a dummy function so Gradio doesn't crash immediately
|
| 35 |
+
def process_email_request(email_body):
|
| 36 |
+
return {"error": "Processing function not found.", "input_email_body": email_body}
|
| 37 |
+
|
| 38 |
+
# Define the Gradio interface
|
| 39 |
+
iface = gr.Interface(
|
| 40 |
+
fn=process_email_request,
|
| 41 |
+
inputs=gr.Textbox(lines=15, label="Input Email Body", placeholder="Paste email content here..."),
|
| 42 |
+
outputs=gr.JSON(label="Processing Results"),
|
| 43 |
+
title="Email Classification and PII Masking API",
|
| 44 |
+
description="Enter the body of an email below. The API will process it to mask PII entities (like names, emails) and classify the email's category. The results will be shown in JSON format.",
|
| 45 |
+
allow_flagging="never" # Optional: Disables flagging/saving examples
|
| 46 |
+
)
|
| 47 |
|
| 48 |
+
# Launch the interface
|
| 49 |
if __name__ == "__main__":
|
| 50 |
if app:
|
| 51 |
# Get port from environment variable PORT, default to 8000
|
|
|
|
| 55 |
print(f"Starting Uvicorn server on host 0.0.0.0, port {port}")
|
| 56 |
uvicorn.run(app, host="0.0.0.0", port=port)
|
| 57 |
else:
|
| 58 |
+
print("Could not start server because the FastAPI app instance was not loaded.")
|
| 59 |
+
iface.launch() # Share=False is default, suitable for HF Spaces
|
combined_emails_with_natural_pii.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b747a5dc74aa834811e194f9779655cd4f87ec30207d8cf63555f407966d6086
|
| 3 |
+
size 13968052
|
requirements.txt
CHANGED
|
@@ -7,7 +7,7 @@ scikit-learn==1.4.2
|
|
| 7 |
joblib==1.4.2
|
| 8 |
|
| 9 |
# --- PII Masking ---
|
| 10 |
-
spacy
|
| 11 |
# The following model is downloaded by spacy CLI, but good to list
|
| 12 |
# en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.7.1/en_core_web_sm-3.7.1-py3-none-any.whl
|
| 13 |
|
|
@@ -17,3 +17,6 @@ spacy
|
|
| 17 |
|
| 18 |
# --- Development/Testing (Optional) ---
|
| 19 |
# requests==2.31.0 # For testing the API or running generate_output.py
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
joblib==1.4.2
|
| 8 |
|
| 9 |
# --- PII Masking ---
|
| 10 |
+
spacy>=3.7,<3.9 # Example: Pin spacy version if needed
|
| 11 |
# The following model is downloaded by spacy CLI, but good to list
|
| 12 |
# en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.7.1/en_core_web_sm-3.7.1-py3-none-any.whl
|
| 13 |
|
|
|
|
| 17 |
|
| 18 |
# --- Development/Testing (Optional) ---
|
| 19 |
# requests==2.31.0 # For testing the API or running generate_output.py
|
| 20 |
+
|
| 21 |
+
# --- Additional Dependencies ---
|
| 22 |
+
gradio # Add gradio
|