Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
import
|
4 |
-
from bs4 import BeautifulSoup
|
5 |
import os
|
6 |
from datetime import datetime # Import datetime for date validation
|
7 |
|
|
|
|
|
|
|
8 |
# Load Groq Cloud API key securely from environment variables
|
9 |
groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
|
10 |
|
@@ -50,12 +52,11 @@ def generate_email_from_groq(bio, company_name, role):
|
|
50 |
print(f"Error: {response.status_code}, {response.text}")
|
51 |
return "Error generating email. Please check your API key or try again later."
|
52 |
|
53 |
-
# Grammar and Tone Checker Function
|
54 |
def check_grammar(email_text):
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
return corrected_text
|
59 |
|
60 |
# Function to validate the DOB format (DD-MM-YYYY)
|
61 |
def validate_dob(dob):
|
@@ -82,7 +83,7 @@ def create_email(name, dob, city, company_name, role, email, phone):
|
|
82 |
# Step 3: Add the user's email, phone number, and LinkedIn profile to the signature
|
83 |
signature = f"\n\nBest regards,\n{name}\nEmail: {email}\nPhone: {phone}\nLinkedIn: {linkedin_profile}"
|
84 |
|
85 |
-
# Step 4: Run grammar and tone check
|
86 |
polished_email = check_grammar(generated_email + signature)
|
87 |
|
88 |
# Return the final polished email with the signature
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
from gramformer import Gramformer
|
|
|
4 |
import os
|
5 |
from datetime import datetime # Import datetime for date validation
|
6 |
|
7 |
+
# Initialize Gramformer (set corrector mode to True)
|
8 |
+
gf = Gramformer(models=1, use_gpu=False) # We set 'use_gpu=False' for Hugging Face Spaces
|
9 |
+
|
10 |
# Load Groq Cloud API key securely from environment variables
|
11 |
groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
|
12 |
|
|
|
52 |
print(f"Error: {response.status_code}, {response.text}")
|
53 |
return "Error generating email. Please check your API key or try again later."
|
54 |
|
55 |
+
# Grammar and Tone Checker Function using Gramformer
|
56 |
def check_grammar(email_text):
|
57 |
+
corrected_sentences = list(gf.correct(email_text))
|
58 |
+
# Return the first corrected sentence (gramformer may return multiple suggestions)
|
59 |
+
return corrected_sentences[0] if corrected_sentences else email_text
|
|
|
60 |
|
61 |
# Function to validate the DOB format (DD-MM-YYYY)
|
62 |
def validate_dob(dob):
|
|
|
83 |
# Step 3: Add the user's email, phone number, and LinkedIn profile to the signature
|
84 |
signature = f"\n\nBest regards,\n{name}\nEmail: {email}\nPhone: {phone}\nLinkedIn: {linkedin_profile}"
|
85 |
|
86 |
+
# Step 4: Run grammar and tone check using Gramformer
|
87 |
polished_email = check_grammar(generated_email + signature)
|
88 |
|
89 |
# Return the final polished email with the signature
|