Manasa1 commited on
Commit
0c8b033
·
verified ·
1 Parent(s): f177b61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -1,17 +1,17 @@
1
- import google.generativeai as genai
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
- GOOGLE_API_KEY = os.getenv("GEMINI_API_KEY")
11
- genai.configure(api_key=GOOGLE_API_KEY)
12
 
13
- # Load Gemini Pro model
14
- model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
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 size if needed (Gemini handles long input, but it's safer)
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 Gemini",
47
- description="Upload a PDF and get a summary using Google's Gemini Pro model."
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__":