Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,12 +9,53 @@ from google.generativeai import types # Add this import
|
|
9 |
COURSE_PDF_URL = "https://huggingface.co/spaces/JeCabrera/copywriter2a/resolve/main/Oferta%20CopyXpert.pdf"
|
10 |
|
11 |
# Simplify PDF content retrieval
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def get_pdf_content():
|
13 |
try:
|
14 |
response = httpx.get(COURSE_PDF_URL)
|
15 |
if response.status_code == 200:
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
except Exception as e:
|
19 |
print(f"Error loading PDF: {e}")
|
20 |
return None
|
|
|
9 |
COURSE_PDF_URL = "https://huggingface.co/spaces/JeCabrera/copywriter2a/resolve/main/Oferta%20CopyXpert.pdf"
|
10 |
|
11 |
# Simplify PDF content retrieval
|
12 |
+
import os
|
13 |
+
import gradio as gr
|
14 |
+
import google.generativeai as genai
|
15 |
+
from dotenv import load_dotenv
|
16 |
+
import httpx
|
17 |
+
from google.generativeai import types
|
18 |
+
|
19 |
+
load_dotenv()
|
20 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
21 |
+
|
22 |
+
# Create a client instance
|
23 |
+
client = genai.Client()
|
24 |
+
|
25 |
+
def verify_pdf_upload(pdf_content):
|
26 |
+
try:
|
27 |
+
# Create a temporary file to store the PDF content
|
28 |
+
temp_file = "temp_course.pdf"
|
29 |
+
with open(temp_file, "wb") as f:
|
30 |
+
f.write(pdf_content)
|
31 |
+
|
32 |
+
# Upload and verify the file
|
33 |
+
file = client.files.upload(temp_file)
|
34 |
+
file_info = client.files.get(file.name)
|
35 |
+
|
36 |
+
print("PDF Verification Status:")
|
37 |
+
print(f"File Name: {file_info.name}")
|
38 |
+
print(f"File Type: {file_info.mime_type}")
|
39 |
+
print(f"File Size: {file_info.size} bytes")
|
40 |
+
|
41 |
+
# Clean up temporary file
|
42 |
+
os.remove(temp_file)
|
43 |
+
return True
|
44 |
+
except Exception as e:
|
45 |
+
print(f"Verification Error: {e}")
|
46 |
+
return False
|
47 |
+
|
48 |
def get_pdf_content():
|
49 |
try:
|
50 |
response = httpx.get(COURSE_PDF_URL)
|
51 |
if response.status_code == 200:
|
52 |
+
content = response.content
|
53 |
+
if verify_pdf_upload(content):
|
54 |
+
print("PDF successfully verified")
|
55 |
+
return content
|
56 |
+
else:
|
57 |
+
print("PDF verification failed")
|
58 |
+
return None
|
59 |
except Exception as e:
|
60 |
print(f"Error loading PDF: {e}")
|
61 |
return None
|