jonathanjordan21 commited on
Commit
3e21b44
1 Parent(s): 03e24bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -1
app.py CHANGED
@@ -1,5 +1,7 @@
1
- from fastapi import FastAPI
2
  from huggingface_hub import HfApi
 
 
3
 
4
  import os
5
 
@@ -25,3 +27,51 @@ def greet_json():
25
 
26
  )
27
  return {"Hello": "World!"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
  from huggingface_hub import HfApi
3
+ from langchain_community.vectorstores.faiss import FAISS
4
+
5
 
6
  import os
7
 
 
27
 
28
  )
29
  return {"Hello": "World!"}
30
+
31
+
32
+ @app.get("/{rand_int}/")
33
+ async def main(rand_int: str, request: Request):
34
+ with open("test.txt", "w") as f:
35
+ f.write(rand_int)
36
+ api = HfApi()
37
+
38
+ api.upload_file(
39
+
40
+ path_or_fileobj="test.txt",
41
+
42
+ path_in_repo="test.txt",
43
+
44
+ repo_id="jonathanjordan21/test-dataset",
45
+
46
+ repo_type="dataset",
47
+
48
+ token = os.getenv("HF_WRITE_TOKEN")
49
+
50
+ )
51
+ return {"raw_url": str(request.url), "message":rand_int}
52
+
53
+
54
+
55
+
56
+ @app.get("/vecs/")
57
+ async def main2(request: Request):
58
+ vecs = FAISS.from_texts(["haha"])
59
+ api = HfApi()
60
+
61
+ vecs.save_local("faiss_index")
62
+
63
+ api.upload_folder(
64
+
65
+ folder_path="faiss_index",
66
+
67
+ repo_id="jonathanjordan21/test-dataset",
68
+
69
+ path_in_repo="vecs/faiss_index",
70
+
71
+ repo_type="dataset",
72
+
73
+ token = os.getenv("HF_WRITE_TOKEN")
74
+
75
+ )
76
+
77
+ return {"raw_url": str(request.url)}