Skip to content

Added Dropbox remote uploader #1258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion application/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ EXPOSE 7091
USER appuser

# Start Gunicorn
CMD ["gunicorn", "-w", "2", "--timeout", "120", "--bind", "0.0.0.0:7091", "application.wsgi:app"]
CMD ["gunicorn", "-w", "2", "--timeout", "120", "--bind", "localhost:7091", "application.wsgi:app"]
5 changes: 4 additions & 1 deletion application/api/user/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ def get(self):
task_meta = task.info
except Exception as err:
return make_response(jsonify({"success": False, "error": str(err)}), 400)


if isinstance(task_meta, Exception):
task_meta = str(task_meta)

return make_response(jsonify({"status": task.status, "result": task_meta}), 200)


Expand Down
24 changes: 24 additions & 0 deletions application/parser/remote/dropbox_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from application.parser.remote.base import BaseRemote
from langchain_community.document_loaders import DropboxLoader

class DropboxLoaderRemote(BaseRemote):
def load_data(self, inputs):
data = eval(inputs)
access_token = data.get("access_token")
folder_path = data.get("folder_path", "")
recursive = True

self.loader = DropboxLoader(
dropbox_access_token=access_token,
dropbox_folder_path=folder_path,
recursive=recursive
)

try:
documents = self.loader.load()
print(f"Loaded {len(documents)} documents from Dropbox")
return documents
except Exception as e:
print(f"Error loading documents from Dropbox: {e}")


2 changes: 2 additions & 0 deletions application/parser/remote/remote_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from application.parser.remote.crawler_loader import CrawlerLoader
from application.parser.remote.web_loader import WebLoader
from application.parser.remote.reddit_loader import RedditPostsLoaderRemote
from application.parser.remote.dropbox_loader import DropboxLoaderRemote
from application.parser.remote.github_loader import GitHubLoader


Expand All @@ -11,6 +12,7 @@ class RemoteCreator:
"sitemap": SitemapLoader,
"crawler": CrawlerLoader,
"reddit": RedditPostsLoaderRemote,
"dropbox" : DropboxLoaderRemote,
"github": GitHubLoader,
}

Expand Down
60 changes: 58 additions & 2 deletions frontend/src/upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function Upload({
const [docName, setDocName] = useState('');
const [urlName, setUrlName] = useState('');
const [url, setUrl] = useState('');
const [dropboxData, setDropboxData] = useState({
access_token: '',
folder_path: '',
});
const [repoUrl, setRepoUrl] = useState(''); // P3f93
const [redditData, setRedditData] = useState({
client_id: '',
Expand All @@ -49,6 +53,7 @@ function Upload({
// { label: 'Sitemap', value: 'sitemap' },
{ label: 'Link', value: 'url' },
{ label: 'Reddit', value: 'reddit' },
{ label: 'Dropbox', value: 'dropbox' },
{ label: 'GitHub', value: 'github' }, // P3f93
];

Expand Down Expand Up @@ -240,6 +245,14 @@ function Upload({
formData.set('name', 'other');
formData.set('data', JSON.stringify(redditData));
}
if (
urlType.value === 'dropbox' &&
dropboxData.access_token.length > 0 &&
dropboxData.folder_path.length > 0
) {
formData.set('name', 'other');
formData.set('data', JSON.stringify(dropboxData));
}
if (urlType.value === 'github') {
formData.append('repo_url', repoUrl); // Pdeac
}
Expand All @@ -255,6 +268,7 @@ function Upload({
setProgress({ type: 'TRAINING', percentage: 0, taskId: task_id });
}, 3000);
};

xhr.open('POST', `${apiHost + '/api/remote'}`);
xhr.send(formData);
};
Expand All @@ -275,7 +289,9 @@ function Upload({
'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
['.docx'],
'text/csv': ['.csv'],
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': ['.xlsx'],
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': [
'.xlsx',
],
},
});

Expand All @@ -288,6 +304,11 @@ function Upload({
...redditData,
[name]: value.split(',').map((item) => item.trim()),
});
} else if (name in dropboxData) {
setDropboxData({
...dropboxData,
[name]: value,
});
} else
setRedditData({
...redditData,
Expand Down Expand Up @@ -382,7 +403,42 @@ function Upload({
size="w-full"
rounded="3xl"
/>
{urlType.label !== 'Reddit' && urlType.label !== 'GitHub' ? (
{urlType.label === 'Dropbox' ? (
<div className="flex flex-col gap-1 mt-2">
<div>
<Input
placeholder="Enter access token"
type="text"
name="access_token"
value={dropboxData.access_token}
onChange={handleChange}
borderVariant="thin"
></Input>
<div className="relative bottom-[52px] left-2">
<span className="bg-white px-2 text-xs text-gray-4000 dark:bg-outer-space dark:text-silver">
Access Token
</span>
</div>
</div>
<div>
<Input
placeholder="Enter folder path"
type="text"
name="folder_path"
value={dropboxData.folder_path}
onChange={handleChange}
borderVariant="thin"
></Input>
<div className="relative bottom-[52px] left-2">
<span className="bg-white px-2 text-xs text-gray-4000 dark:bg-outer-space dark:text-silver">
Folder Path
</span>
</div>
</div>
</div>
) : urlType.label !== 'Reddit' &&
urlType.label !== 'GitHub' &&
urlType.label !== 'Dropbox' ? (
<>
<Input
placeholder={`Enter ${t('modals.uploadDoc.name')}`}
Expand Down
Loading