Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
import os
|
| 2 |
-
|
|
|
|
| 3 |
from dotenv import load_dotenv
|
|
|
|
| 4 |
|
| 5 |
# Load environment variables from a .env file
|
| 6 |
load_dotenv()
|
|
@@ -9,13 +11,9 @@ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
|
| 9 |
# Instantiate the Groq client
|
| 10 |
client = Groq(api_key=GROQ_API_KEY)
|
| 11 |
|
| 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 = ""
|
| 18 |
-
with pdfplumber.open(pdf_file) as pdf:
|
| 19 |
for page in pdf.pages:
|
| 20 |
page_text = page.extract_text()
|
| 21 |
if page_text:
|
|
@@ -33,8 +31,16 @@ def summarize_pdf(pdf_file):
|
|
| 33 |
prompt = f"Summarize the following PDF content:\n\n{text}"
|
| 34 |
|
| 35 |
try:
|
| 36 |
-
response =
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
except Exception as e:
|
| 39 |
return f"Error during summarization: {e}"
|
| 40 |
|
|
|
|
| 1 |
import os
|
| 2 |
+
import pdfplumber
|
| 3 |
+
import gradio as gr
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
+
from groq import Groq
|
| 6 |
|
| 7 |
# Load environment variables from a .env file
|
| 8 |
load_dotenv()
|
|
|
|
| 11 |
# Instantiate the Groq client
|
| 12 |
client = Groq(api_key=GROQ_API_KEY)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def extract_text_from_pdf(pdf_file):
|
| 15 |
text = ""
|
| 16 |
+
with pdfplumber.open(pdf_file.name) as pdf:
|
| 17 |
for page in pdf.pages:
|
| 18 |
page_text = page.extract_text()
|
| 19 |
if page_text:
|
|
|
|
| 31 |
prompt = f"Summarize the following PDF content:\n\n{text}"
|
| 32 |
|
| 33 |
try:
|
| 34 |
+
response = client.chat.completions.create(
|
| 35 |
+
messages=[
|
| 36 |
+
{
|
| 37 |
+
"role": "user",
|
| 38 |
+
"content": prompt
|
| 39 |
+
}
|
| 40 |
+
],
|
| 41 |
+
model="llama3-8b-8192", # Replace with your desired model ID
|
| 42 |
+
)
|
| 43 |
+
return response.choices[0].message.content.strip()
|
| 44 |
except Exception as e:
|
| 45 |
return f"Error during summarization: {e}"
|
| 46 |
|