Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
from PyPDF2 import PdfReader
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
DEEPSEEK_API_KEY =
|
| 8 |
|
| 9 |
-
#
|
| 10 |
def extract_pdf_text(pdf_file):
|
| 11 |
reader = PdfReader(pdf_file)
|
| 12 |
text = ""
|
|
@@ -14,7 +14,7 @@ def extract_pdf_text(pdf_file):
|
|
| 14 |
text += page.extract_text() or ""
|
| 15 |
return text.strip()
|
| 16 |
|
| 17 |
-
#
|
| 18 |
def ask_pdf(pdf_file, question):
|
| 19 |
if not pdf_file or not question:
|
| 20 |
return "β οΈ Please upload a PDF and enter a question."
|
|
@@ -42,34 +42,53 @@ def ask_pdf(pdf_file, question):
|
|
| 42 |
except Exception as e:
|
| 43 |
return f"β Error: {e}"
|
| 44 |
|
| 45 |
-
#
|
| 46 |
with gr.Blocks(css="""
|
| 47 |
body {
|
| 48 |
-
background-color: #
|
| 49 |
-
color: #
|
| 50 |
-
font-family: '
|
| 51 |
}
|
| 52 |
.gr-button {
|
| 53 |
-
background
|
| 54 |
color: white;
|
| 55 |
font-weight: bold;
|
| 56 |
-
border-radius:
|
| 57 |
-
|
| 58 |
-
|
| 59 |
}
|
| 60 |
.gr-button:hover {
|
| 61 |
-
background
|
|
|
|
| 62 |
}
|
| 63 |
-
.gr-
|
|
|
|
|
|
|
| 64 |
border-radius: 10px;
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
}
|
| 69 |
""") as demo:
|
| 70 |
gr.Markdown("""
|
| 71 |
-
<
|
| 72 |
-
<
|
| 73 |
""")
|
| 74 |
|
| 75 |
with gr.Row():
|
|
@@ -77,9 +96,10 @@ with gr.Blocks(css="""
|
|
| 77 |
pdf_input = gr.File(label="π Upload your PDF", file_types=[".pdf"])
|
| 78 |
question_input = gr.Textbox(label="β Ask a question about your PDF", placeholder="e.g. Summarize this document...", lines=2)
|
| 79 |
btn = gr.Button("π Ask the PDF")
|
|
|
|
| 80 |
with gr.Column():
|
| 81 |
-
output = gr.Textbox(label="π‘ Answer", lines=
|
| 82 |
|
| 83 |
btn.click(fn=ask_pdf, inputs=[pdf_input, question_input], outputs=output)
|
| 84 |
|
| 85 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
import os
|
| 4 |
+
from PyPDF2 import PdfReader
|
| 5 |
|
| 6 |
+
# Add your DeepSeek API Key
|
| 7 |
+
DEEPSEEK_API_KEY = "sk-e6ea7f5c0ba049c0a89d2fec134e0126"
|
| 8 |
|
| 9 |
+
# Function to extract text from uploaded PDF
|
| 10 |
def extract_pdf_text(pdf_file):
|
| 11 |
reader = PdfReader(pdf_file)
|
| 12 |
text = ""
|
|
|
|
| 14 |
text += page.extract_text() or ""
|
| 15 |
return text.strip()
|
| 16 |
|
| 17 |
+
# Ask a question based on PDF content
|
| 18 |
def ask_pdf(pdf_file, question):
|
| 19 |
if not pdf_file or not question:
|
| 20 |
return "β οΈ Please upload a PDF and enter a question."
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
return f"β Error: {e}"
|
| 44 |
|
| 45 |
+
# Gradio UI with updated modern design
|
| 46 |
with gr.Blocks(css="""
|
| 47 |
body {
|
| 48 |
+
background-color: #111;
|
| 49 |
+
color: #f5f5f5;
|
| 50 |
+
font-family: 'Inter', sans-serif;
|
| 51 |
}
|
| 52 |
.gr-button {
|
| 53 |
+
background: #6a0dad;
|
| 54 |
color: white;
|
| 55 |
font-weight: bold;
|
| 56 |
+
border-radius: 8px;
|
| 57 |
+
border: 2px solid #6a0dad;
|
| 58 |
+
transition: 0.3s;
|
| 59 |
}
|
| 60 |
.gr-button:hover {
|
| 61 |
+
background: #8e44ad;
|
| 62 |
+
border-color: #8e44ad;
|
| 63 |
}
|
| 64 |
+
.gr-box, .gr-textbox, .gr-file {
|
| 65 |
+
background-color: #1c1c1c;
|
| 66 |
+
border: 1px solid #333;
|
| 67 |
border-radius: 10px;
|
| 68 |
+
color: white;
|
| 69 |
+
}
|
| 70 |
+
footer {
|
| 71 |
+
visibility: hidden;
|
| 72 |
+
}
|
| 73 |
+
.title {
|
| 74 |
+
font-size: 2.4rem;
|
| 75 |
+
text-align: center;
|
| 76 |
+
font-weight: 700;
|
| 77 |
+
margin-top: 1.5rem;
|
| 78 |
+
background: linear-gradient(to right, #ff4ecb, #8873f5);
|
| 79 |
+
-webkit-background-clip: text;
|
| 80 |
+
-webkit-text-fill-color: transparent;
|
| 81 |
+
}
|
| 82 |
+
.subtitle {
|
| 83 |
+
font-size: 1.2rem;
|
| 84 |
+
text-align: center;
|
| 85 |
+
color: #aaa;
|
| 86 |
+
margin-bottom: 2rem;
|
| 87 |
}
|
| 88 |
""") as demo:
|
| 89 |
gr.Markdown("""
|
| 90 |
+
<div class="title">β¨ PDF Genius Chatbot</div>
|
| 91 |
+
<div class="subtitle">Ask your PDFs anything β powered by DeepSeek AI</div>
|
| 92 |
""")
|
| 93 |
|
| 94 |
with gr.Row():
|
|
|
|
| 96 |
pdf_input = gr.File(label="π Upload your PDF", file_types=[".pdf"])
|
| 97 |
question_input = gr.Textbox(label="β Ask a question about your PDF", placeholder="e.g. Summarize this document...", lines=2)
|
| 98 |
btn = gr.Button("π Ask the PDF")
|
| 99 |
+
|
| 100 |
with gr.Column():
|
| 101 |
+
output = gr.Textbox(label="π‘ Answer", lines=14)
|
| 102 |
|
| 103 |
btn.click(fn=ask_pdf, inputs=[pdf_input, question_input], outputs=output)
|
| 104 |
|
| 105 |
+
demo.launch(share=True)
|