safiaa02 commited on
Commit
ac5e4f7
ยท
verified ยท
1 Parent(s): d1c1d46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
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
- return email_text, classification_result, rewritten_email
 
 
 
 
 
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.Textbox(label="Original Email", lines=12)
67
- classification_out = gr.Textbox(label="Phishing Detection Result", lines=4)
68
- rewritten_out = gr.Textbox(label="Safe Rewritten Email", lines=12)
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,