Jofthomas HF staff commited on
Commit
ee795ac
1 Parent(s): af615c0

Blocking other spaces

Browse files
Files changed (1) hide show
  1. TextGen/router.py +20 -12
TextGen/router.py CHANGED
@@ -168,25 +168,27 @@ def inference_model(system_messsage, prompt):
168
 
169
  @app.get("/", tags=["Home"])
170
  def api_home(request: Request):
171
- client_ip = request.client.host
172
- print(client_ip)
173
  return {'detail': 'Everchanging Quest backend, nothing to see here'}
174
 
175
  @app.post("/api/generate", summary="Generate text from prompt", tags=["Generate"], response_model=Generate)
176
- def inference(message: Message):
 
 
177
  return generate_text(messages=message.messages, npc=message.npc)
178
 
179
  @app.post("/invoke_model")
180
- def story(prompt: Invoke):
 
 
181
  return inference_model(system_messsage=prompt.system_prompt,prompt=prompt.message)
182
 
183
  @app.post("/generate_level")
184
  def placement(input: Rooms, request: Request):
185
- origin = request.headers.get("origin")
186
- referer = request.headers.get("referer")
187
- print("origin : ", origin)
188
- print("referer : ", referer)
189
- print(input)
190
  markdown_map=generate_map_markdown(input.rooms,input.room_of_interest,input.index_exit)
191
  story=generate_story(input.possible_entities)
192
  print(story)
@@ -195,7 +197,9 @@ def placement(input: Rooms, request: Request):
195
  return placements
196
 
197
  @app.post("/check_right_to_pass")
198
- def check(input: Logs):
 
 
199
  print(input.logs)
200
  system_prompt="You are a game master in a roguelike. You previously decided of an objective for the player. You have to answer with YES or NO on wether the objective as been sucessfully completed. Be kind and flexible as the content of the game is AI generated and might not be feasible."
201
  user_message=f"The objective was : {input.objective} and the player did the following actions : {input.logs}. Do you grant acess ? ONLY answer YES or NO"
@@ -259,7 +263,9 @@ async def generate_wav(message: VoiceMessage):
259
 
260
  @app.get("/generate_voice_eleven", response_class=StreamingResponse)
261
  @app.post("/generate_voice_eleven", response_class=StreamingResponse)
262
- def generate_voice_eleven(message: VoiceMessage = None):
 
 
263
  global Last_message # Declare Last_message as global
264
  if message is None:
265
  message = Last_message
@@ -308,7 +314,9 @@ def generate_voice_eleven(message: VoiceMessage = None):
308
  # return StreamingResponse(audio_stream(),media_type="audio/mpeg")
309
  @app.post("/generate_song")
310
  @app.get("/generate_song")
311
- async def generate_song(request:SongRequest):
 
 
312
  backstory=main_npc_system_prompts["Bard"]
313
  print(backstory)
314
  text=f"""the story is about a little girl in red hood adventuring in the dungeon behind the portal.{backstory} /n The user requested a song about : {request.prompt}"""
 
168
 
169
  @app.get("/", tags=["Home"])
170
  def api_home(request: Request):
171
+ if request.headers.get("origin") != "https://jofthomas-everchanging-quest.static.hf.space":
172
+ return
173
  return {'detail': 'Everchanging Quest backend, nothing to see here'}
174
 
175
  @app.post("/api/generate", summary="Generate text from prompt", tags=["Generate"], response_model=Generate)
176
+ def inference(message: Message, request: Request):
177
+ if request.headers.get("origin") != "https://jofthomas-everchanging-quest.static.hf.space":
178
+ return
179
  return generate_text(messages=message.messages, npc=message.npc)
180
 
181
  @app.post("/invoke_model")
182
+ def story(prompt: Invoke,request: Request):
183
+ if request.headers.get("origin") != "https://jofthomas-everchanging-quest.static.hf.space":
184
+ return
185
  return inference_model(system_messsage=prompt.system_prompt,prompt=prompt.message)
186
 
187
  @app.post("/generate_level")
188
  def placement(input: Rooms, request: Request):
189
+ print(request.headers)
190
+ if request.headers.get("origin") != "https://jofthomas-everchanging-quest.static.hf.space":
191
+ return
 
 
192
  markdown_map=generate_map_markdown(input.rooms,input.room_of_interest,input.index_exit)
193
  story=generate_story(input.possible_entities)
194
  print(story)
 
197
  return placements
198
 
199
  @app.post("/check_right_to_pass")
200
+ def check(input: Logs,request: Request):
201
+ if request.headers.get("origin") != "https://jofthomas-everchanging-quest.static.hf.space":
202
+ return
203
  print(input.logs)
204
  system_prompt="You are a game master in a roguelike. You previously decided of an objective for the player. You have to answer with YES or NO on wether the objective as been sucessfully completed. Be kind and flexible as the content of the game is AI generated and might not be feasible."
205
  user_message=f"The objective was : {input.objective} and the player did the following actions : {input.logs}. Do you grant acess ? ONLY answer YES or NO"
 
263
 
264
  @app.get("/generate_voice_eleven", response_class=StreamingResponse)
265
  @app.post("/generate_voice_eleven", response_class=StreamingResponse)
266
+ def generate_voice_eleven(message: VoiceMessage = None,request: Request):
267
+ if request.headers.get("origin") != "https://jofthomas-everchanging-quest.static.hf.space":
268
+ return
269
  global Last_message # Declare Last_message as global
270
  if message is None:
271
  message = Last_message
 
314
  # return StreamingResponse(audio_stream(),media_type="audio/mpeg")
315
  @app.post("/generate_song")
316
  @app.get("/generate_song")
317
+ async def generate_song(request:SongRequest,request: Request):
318
+ if request.headers.get("origin") != "https://jofthomas-everchanging-quest.static.hf.space":
319
+ return
320
  backstory=main_npc_system_prompts["Bard"]
321
  print(backstory)
322
  text=f"""the story is about a little girl in red hood adventuring in the dungeon behind the portal.{backstory} /n The user requested a song about : {request.prompt}"""