CaesarCloudSync commited on
Commit
1a27815
1 Parent(s): b2e71f3

CaesarAIART test

Browse files
Files changed (4) hide show
  1. CaesarAIART/caesaraiart.py +18 -0
  2. RequestModels.py +2 -1
  3. main.py +17 -3
  4. requirements.txt +3 -0
CaesarAIART/caesaraiart.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import StableDiffusionPipeline
3
+
4
+ class CaesarAIART:
5
+ def __init__(self,CURRENT_DIR=""):
6
+ self.model_id = "CompVis/stable-diffusion-v1-4"
7
+ self.device = "cuda"
8
+ self.pipe = StableDiffusionPipeline.from_pretrained(self.model_id, torch_dtype=torch.float16)
9
+ self.CURRENT_DIR = CURRENT_DIR
10
+ self.pipe = self.pipe.to(self.device)
11
+ def generate(self,prompt):
12
+ image = self.pipe(prompt).images[0]
13
+ image.save(f"{self.CURRENT_DIR}/CaesarAIART/caesarart.png")
14
+
15
+ if __name__ == "__main__":
16
+ prompt = "a photo of an astronaut riding a horse on mars"
17
+ caesaraiart = CaesarAIART()
18
+ caesaraiart.generate()
RequestModels.py CHANGED
@@ -33,7 +33,8 @@ class CaesarStockInfoModel(BaseModel):
33
  class CaesarTelegramMessageModel(BaseModel):
34
  chat_id: str
35
  message: str
36
-
 
37
  class CaesarVoiceModel(BaseModel):
38
  filename: Union[str,None]
39
  language: Union[str,None]
 
33
  class CaesarTelegramMessageModel(BaseModel):
34
  chat_id: str
35
  message: str
36
+ class CaesarAIARTModel(BaseModel):
37
+ prompt: str
38
  class CaesarVoiceModel(BaseModel):
39
  filename: Union[str,None]
40
  language: Union[str,None]
main.py CHANGED
@@ -28,14 +28,17 @@ from CaesarVoice import CaesarVoice
28
  from csv_to_db import ImportCSV
29
  from RequestModels import *
30
  from CaesarFaceRecognition.caesardeepface import CaesarDeepFace
31
- from CaesarAIMusicLoad.caesaraimusicload import CaesarAITelegramBOT
 
32
  importcsv = ImportCSV("CaesarAI")
33
  caesaryolo = CaesarYolo()
34
  caesarfacedetectmodel = CaesarFaceDetection()
35
- caesartelgegrambot = CaesarAITelegramBOT()
 
36
  app = FastAPI()
37
 
38
  CURRENT_DIR = os.path.realpath(__file__).replace(f"/main.py","")
 
39
  app.add_middleware(
40
  CORSMiddleware,
41
  allow_origins=["*"], # can alter with time
@@ -92,6 +95,7 @@ async def caesarfacedetect(websocket: WebSocket):
92
 
93
  except WebSocketDisconnect:
94
  print("Client disconnected")
 
95
  @app.get("/getcaesartelegramchatids")
96
  def getcaesartelegramchatid():
97
  try:
@@ -109,7 +113,7 @@ def caesartelegramsendmessage(messageinfo: CaesarTelegramMessageModel):
109
  return chatids
110
  except Exception as ex:
111
  return {"error":f"{type(ex)},{ex}"}
112
-
113
  @app.post("/caesarfacesnap")
114
  def caesarfacesnap(frames: CaesarOCRHTTPModel):
115
  try:
@@ -126,6 +130,16 @@ def caesarfacesnap(frames: CaesarOCRHTTPModel):
126
  except Exception as ex:
127
  return {"error":f"{type(ex)},{ex}"}
128
 
 
 
 
 
 
 
 
 
 
 
129
  @app.post("/faceauthorizeuser")
130
  def faceauthorizeuser(recogperson: CaesarFaceAuth = Depends(),file: UploadFile = File(...)):
131
 
 
28
  from csv_to_db import ImportCSV
29
  from RequestModels import *
30
  from CaesarFaceRecognition.caesardeepface import CaesarDeepFace
31
+ from CaesarAIART.caesaraiart import CaesarAIART
32
+ #from CaesarAIMusicLoad.caesaraimusicload import CaesarAITelegramBOT
33
  importcsv = ImportCSV("CaesarAI")
34
  caesaryolo = CaesarYolo()
35
  caesarfacedetectmodel = CaesarFaceDetection()
36
+ #caesartelgegrambot = CaesarAITelegramBOT()
37
+
38
  app = FastAPI()
39
 
40
  CURRENT_DIR = os.path.realpath(__file__).replace(f"/main.py","")
41
+ caesaraiart = CaesarAIART(CURRENT_DIR)
42
  app.add_middleware(
43
  CORSMiddleware,
44
  allow_origins=["*"], # can alter with time
 
95
 
96
  except WebSocketDisconnect:
97
  print("Client disconnected")
98
+ """
99
  @app.get("/getcaesartelegramchatids")
100
  def getcaesartelegramchatid():
101
  try:
 
113
  return chatids
114
  except Exception as ex:
115
  return {"error":f"{type(ex)},{ex}"}
116
+ """
117
  @app.post("/caesarfacesnap")
118
  def caesarfacesnap(frames: CaesarOCRHTTPModel):
119
  try:
 
130
  except Exception as ex:
131
  return {"error":f"{type(ex)},{ex}"}
132
 
133
+ @app.post("/caesaraiart")
134
+ def caesarart(promptjson: CaesarAIARTModel):
135
+ try:
136
+ promptjson = dict(promptjson)
137
+ caesaraiart.generate(promptjson["prompt"])
138
+ return FileResponse(f"{CURRENT_DIR}/CaesarAIART/caesarart.png")
139
+
140
+ except Exception as ex:
141
+ return {"error":f"{type(ex)},{ex}"}
142
+
143
  @app.post("/faceauthorizeuser")
144
  def faceauthorizeuser(recogperson: CaesarFaceAuth = Depends(),file: UploadFile = File(...)):
145
 
requirements.txt CHANGED
@@ -103,6 +103,9 @@ tensorboard-plugin-wit==1.8.1
103
  tensorflow==2.11.0
104
  tensorflow-estimator==2.11.0
105
  tensorflow-intel
 
 
 
106
  tensorflow-io-gcs-filesystem==0.31.0
107
  termcolor==2.2.0
108
  thinc==8.1.7
 
103
  tensorflow==2.11.0
104
  tensorflow-estimator==2.11.0
105
  tensorflow-intel
106
+ diffusers
107
+ scipy
108
+ accelerate
109
  tensorflow-io-gcs-filesystem==0.31.0
110
  termcolor==2.2.0
111
  thinc==8.1.7