gnumanth commited on
Commit
21931b3
·
verified ·
1 Parent(s): 9588578

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -45
app.py CHANGED
@@ -9,8 +9,9 @@ from pathlib import Path
9
  md = MarkItDown()
10
 
11
  # Configure Gemini AI
12
- genai.configure(api_key=os.getenv('GEMINI_KEY'))
13
- model = genai.GenerativeModel('gemini-1.5-flash')
 
14
 
15
  def process_with_markitdown(input_path):
16
  """Process file or URL with MarkItDown and return text content"""
@@ -85,19 +86,23 @@ async def process_input(input_text, uploaded_file=None):
85
  except Exception as e:
86
  return f"Error processing input: {str(e)}"
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  # Create Gradio interface with drag-and-drop
89
- with gr.Blocks(css="""
90
- .upload-box {
91
- border: 2px dashed #ccc;
92
- border-radius: 8px;
93
- padding: 20px;
94
- text-align: center;
95
- transition: border-color 0.3s ease;
96
- }
97
- .upload-box:hover, .upload-box.dragover {
98
- border-color: #666;
99
- }
100
- """) as iface:
101
  gr.Markdown("# Text Summarization Tool")
102
  gr.Markdown("Enter a URL, paste text, or drag & drop a file to get a summary.")
103
 
@@ -126,35 +131,15 @@ with gr.Blocks(css="""
126
 
127
  output_text = gr.Textbox(label="Summary", lines=10)
128
 
129
- # Add JavaScript for drag-and-drop highlighting
130
- gr.JS("""
131
- function setupDragDrop() {
132
- const uploadBox = document.querySelector('.upload-box');
133
-
134
- ['dragenter', 'dragover'].forEach(eventName => {
135
- uploadBox.addEventListener(eventName, (e) => {
136
- e.preventDefault();
137
- uploadBox.classList.add('dragover');
138
- });
139
- });
140
-
141
- ['dragleave', 'drop'].forEach(eventName => {
142
- uploadBox.addEventListener(eventName, (e) => {
143
- e.preventDefault();
144
- uploadBox.classList.remove('dragover');
145
- });
146
- });
147
- }
148
-
149
- // Call setup when the page loads
150
- if (document.readyState === 'complete') {
151
- setupDragDrop();
152
- } else {
153
- window.addEventListener('load', setupDragDrop);
154
- }
155
- """)
156
 
157
- # Set up event handlers
158
  submit_btn.click(
159
  fn=process_input,
160
  inputs=[input_text, file_upload],
@@ -175,6 +160,3 @@ with gr.Blocks(css="""
175
  ],
176
  inputs=input_text
177
  )
178
-
179
- if __name__ == "__main__":
180
- iface.launch()
 
9
  md = MarkItDown()
10
 
11
  # Configure Gemini AI
12
+ GOOGLE_API_KEY = "your_api_key_here" # Replace with your actual API key
13
+ genai.configure(api_key=GOOGLE_API_KEY)
14
+ model = genai.GenerativeModel('gemini-pro')
15
 
16
  def process_with_markitdown(input_path):
17
  """Process file or URL with MarkItDown and return text content"""
 
86
  except Exception as e:
87
  return f"Error processing input: {str(e)}"
88
 
89
+ # Custom CSS for drag-and-drop styling
90
+ custom_css = """
91
+ .upload-box {
92
+ border: 2px dashed #ccc !important;
93
+ border-radius: 8px !important;
94
+ padding: 20px !important;
95
+ text-align: center !important;
96
+ transition: all 0.3s ease !important;
97
+ }
98
+ .upload-box:hover {
99
+ border-color: #666 !important;
100
+ background-color: rgba(0, 0, 0, 0.05) !important;
101
+ }
102
+ """
103
+
104
  # Create Gradio interface with drag-and-drop
105
+ with gr.Blocks(css=custom_css) as iface:
 
 
 
 
 
 
 
 
 
 
 
106
  gr.Markdown("# Text Summarization Tool")
107
  gr.Markdown("Enter a URL, paste text, or drag & drop a file to get a summary.")
108
 
 
131
 
132
  output_text = gr.Textbox(label="Summary", lines=10)
133
 
134
+ # Event handlers for drag and drop using Gradio's event system
135
+ file_upload.upload(
136
+ fn=lambda: None,
137
+ inputs=None,
138
+ outputs=None,
139
+ _js="() => {document.querySelector('.upload-box').classList.remove('dragover');}"
140
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
+ # Set up event handlers for the buttons
143
  submit_btn.click(
144
  fn=process_input,
145
  inputs=[input_text, file_upload],
 
160
  ],
161
  inputs=input_text
162
  )