Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,17 @@
|
|
| 1 |
-
import
|
| 2 |
import pdfplumber
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
-
load_dotenv()
|
| 7 |
|
|
|
|
| 8 |
|
| 9 |
-
# Replace with your API key
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
# Load
|
| 14 |
-
model =
|
| 15 |
|
| 16 |
def extract_text_from_pdf(pdf_file):
|
| 17 |
text = ""
|
|
@@ -27,13 +27,13 @@ def summarize_pdf(pdf_file):
|
|
| 27 |
if not text.strip():
|
| 28 |
return "No extractable text found in the PDF."
|
| 29 |
|
| 30 |
-
# Limit text
|
| 31 |
text = text[:15000]
|
| 32 |
|
| 33 |
prompt = f"Summarize the following PDF content:\n\n{text}"
|
| 34 |
|
| 35 |
try:
|
| 36 |
-
response = model.generate_content(prompt)
|
| 37 |
return response.text.strip()
|
| 38 |
except Exception as e:
|
| 39 |
return f"Error during summarization: {e}"
|
|
@@ -43,8 +43,8 @@ iface = gr.Interface(
|
|
| 43 |
fn=summarize_pdf,
|
| 44 |
inputs=gr.File(label="Upload PDF", file_types=[".pdf"]),
|
| 45 |
outputs="text",
|
| 46 |
-
title="PDF Summarizer with
|
| 47 |
-
description="Upload a PDF and get a summary using
|
| 48 |
)
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
import groq # This assumes Groq provides a Python package named "groq"
|
| 2 |
import pdfplumber
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
| 5 |
from dotenv import load_dotenv
|
|
|
|
| 6 |
|
| 7 |
+
load_dotenv() # Loads environment variables from a .env file
|
| 8 |
|
| 9 |
+
# Replace with your Groq API key in your .env file as GROQ_API_KEY
|
| 10 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 11 |
+
groq.configure(api_key=GROQ_API_KEY)
|
| 12 |
|
| 13 |
+
# Load Groq's generative model (the model name 'groq-pro' is illustrative)
|
| 14 |
+
model = groq.GenerativeModel('groq-pro')
|
| 15 |
|
| 16 |
def extract_text_from_pdf(pdf_file):
|
| 17 |
text = ""
|
|
|
|
| 27 |
if not text.strip():
|
| 28 |
return "No extractable text found in the PDF."
|
| 29 |
|
| 30 |
+
# Optional: Limit the text if needed for token limits
|
| 31 |
text = text[:15000]
|
| 32 |
|
| 33 |
prompt = f"Summarize the following PDF content:\n\n{text}"
|
| 34 |
|
| 35 |
try:
|
| 36 |
+
response = model.generate_content(prompt) # Adjust parameters per Groq's API
|
| 37 |
return response.text.strip()
|
| 38 |
except Exception as e:
|
| 39 |
return f"Error during summarization: {e}"
|
|
|
|
| 43 |
fn=summarize_pdf,
|
| 44 |
inputs=gr.File(label="Upload PDF", file_types=[".pdf"]),
|
| 45 |
outputs="text",
|
| 46 |
+
title="PDF Summarizer with Groq",
|
| 47 |
+
description="Upload a PDF and get a summary using Groq's generative AI API."
|
| 48 |
)
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|