tykiww commited on
Commit
0f115b9
·
verified ·
1 Parent(s): 037a4b0

Create server.py

Browse files
Files changed (1) hide show
  1. server.py +35 -0
server.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import json
3
+ from datasets import load_dataset
4
+
5
+
6
+
7
+ class get_files:
8
+
9
+ def predefined_dataset(dataset_name):
10
+ global dataset # bad practice, I know... But just bear with me. Will later update to state dict.
11
+ dataset = load_dataset(dataset_name, split = "train")
12
+ return 'Successfully loaded dataset'
13
+
14
+ def uploaded_dataset(file):
15
+ global dataset # bad practice, I know... But just bear with me. Will later update to state dict.
16
+ dataset = []
17
+ if file is None:
18
+ return "File not found. Please upload the file again."
19
+ try:
20
+ with open(file,'r') as file:
21
+ for line in file:
22
+ dataset.append(json.loads(line.strip()))
23
+ return "File retrieved."
24
+ except FileNotFoundError:
25
+ return "File not found. Please upload the file again."
26
+
27
+ def load_markdown_file(file_path):
28
+ try:
29
+ with open(file_path, 'r') as f:
30
+ return f.read()
31
+ except FileNotFoundError:
32
+ return "File not found. Please check the file path."
33
+ except Exception as e:
34
+ return f"Error loading file: {str(e)}"
35
+