BraWler666 commited on
Commit
f9002bb
Β·
verified Β·
1 Parent(s): a28f0ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -22
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
- # πŸ” Your DeepSeek API Key
7
- DEEPSEEK_API_KEY = os.environ.get("DEEPSEEK_API_KEY", "your-key-here")
8
 
9
- # πŸ“„ Extract text from PDF
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
- # 🧠 Ask questions about the PDF
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
- # 🎨 Interface layout and design
46
  with gr.Blocks(css="""
47
  body {
48
- background-color: #121212;
49
- color: #ffffff;
50
- font-family: 'Segoe UI', sans-serif;
51
  }
52
  .gr-button {
53
- background-color: #a29bfe;
54
  color: white;
55
  font-weight: bold;
56
- border-radius: 10px;
57
- padding: 0.75em 1em;
58
- font-size: 1em;
59
  }
60
  .gr-button:hover {
61
- background-color: #6c5ce7;
 
62
  }
63
- .gr-file, .gr-textbox {
 
 
64
  border-radius: 10px;
65
- border: 1px solid #444;
66
- background-color: #2b2b2b;
67
- color: #eee;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  }
69
  """) as demo:
70
  gr.Markdown("""
71
- <h1 style="text-align:center; color:#e0b3ff;">✨ PDF Genius Chatbot</h1>
72
- <p style="text-align:center; font-size: 1.1em; color:#bbb;">Ask your PDFs anything β€” powered by DeepSeek AI</p>
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=15)
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)