Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,14 +2,11 @@ import gradio as gr
|
|
| 2 |
from groq import Groq
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# โ ๏ธ IMPORTANT: Set your Groq API key in Hugging Face Spaces "Secrets"
|
| 6 |
-
# os.environ["GROQ_API_KEY"] = "your_api_key_here"
|
| 7 |
-
|
| 8 |
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
| 9 |
|
| 10 |
def analyze_email(email_text):
|
| 11 |
if not email_text.strip():
|
| 12 |
-
return "โ ๏ธ Please paste an email to analyze
|
| 13 |
|
| 14 |
# Step 1: Detect if phishing
|
| 15 |
detection_prompt = f"""
|
|
@@ -45,7 +42,12 @@ def analyze_email(email_text):
|
|
| 45 |
|
| 46 |
rewritten_email = rewrite_response.choices[0].message.content.strip()
|
| 47 |
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
# ๐ Gradio UI
|
|
@@ -63,9 +65,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 63 |
analyze_btn = gr.Button("๐ Analyze Email")
|
| 64 |
|
| 65 |
with gr.Row():
|
| 66 |
-
original_out = gr.
|
| 67 |
-
classification_out = gr.
|
| 68 |
-
rewritten_out = gr.
|
| 69 |
|
| 70 |
analyze_btn.click(
|
| 71 |
analyze_email,
|
|
|
|
| 2 |
from groq import Groq
|
| 3 |
import os
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
| 6 |
|
| 7 |
def analyze_email(email_text):
|
| 8 |
if not email_text.strip():
|
| 9 |
+
return "โ ๏ธ **Please paste an email to analyze.**", "", ""
|
| 10 |
|
| 11 |
# Step 1: Detect if phishing
|
| 12 |
detection_prompt = f"""
|
|
|
|
| 42 |
|
| 43 |
rewritten_email = rewrite_response.choices[0].message.content.strip()
|
| 44 |
|
| 45 |
+
# Return formatted Markdown
|
| 46 |
+
original_md = f"### โ๏ธ Original Email\n\n```\n{email_text}\n```"
|
| 47 |
+
classification_md = f"### ๐ก๏ธ Detection Result\n\n{classification_result}"
|
| 48 |
+
rewritten_md = f"### โ
Safe Rewritten Email\n\n{rewritten_email}"
|
| 49 |
+
|
| 50 |
+
return original_md, classification_md, rewritten_md
|
| 51 |
|
| 52 |
|
| 53 |
# ๐ Gradio UI
|
|
|
|
| 65 |
analyze_btn = gr.Button("๐ Analyze Email")
|
| 66 |
|
| 67 |
with gr.Row():
|
| 68 |
+
original_out = gr.Markdown()
|
| 69 |
+
classification_out = gr.Markdown()
|
| 70 |
+
rewritten_out = gr.Markdown()
|
| 71 |
|
| 72 |
analyze_btn.click(
|
| 73 |
analyze_email,
|