Jofthomas HF staff commited on
Commit
a3e8ddf
1 Parent(s): bb41ed4

Blocked other spaces from accessing my backend.

Browse files
Files changed (1) hide show
  1. TextGen/router.py +19 -17
TextGen/router.py CHANGED
@@ -169,26 +169,26 @@ def inference_model(system_messsage, prompt):
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)
@@ -199,7 +199,7 @@ def placement(input: Rooms, request: Request):
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"
@@ -265,7 +265,7 @@ async def generate_wav(message: VoiceMessage):
265
  @app.post("/generate_voice_eleven", response_class=StreamingResponse)
266
  def generate_voice_eleven(request: Request, message: VoiceMessage = None):
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
@@ -316,7 +316,7 @@ def generate_voice_eleven(request: Request, message: VoiceMessage = None):
316
  @app.get("/generate_song")
317
  async def generate_song(request:SongRequest,httprequest: Request):
318
  if httprequest.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}"""
@@ -324,16 +324,18 @@ async def generate_song(request:SongRequest,httprequest: Request):
324
  song_lyrics=generate_lyrics({
325
  "prompt": f"{text}",
326
  })
327
- print(song_lyrics['text'])
328
- data = custom_generate_audio({
329
- "prompt": song_lyrics['text'],
330
- "tags": "male bard",
331
- "title":"Everchangin_Quest_song",
332
- "wait_audio":True,
333
-
334
- })
335
- infos=get_audio_information(f"{data[0]['id']},{data[1]['id']}")
336
- return infos
 
 
337
 
338
  #@app.post('/generate_image')
339
  #def Imagen(image:ImageGen=None):
 
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 204
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 204
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 204
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 204
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)
 
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 204
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"
 
265
  @app.post("/generate_voice_eleven", response_class=StreamingResponse)
266
  def generate_voice_eleven(request: Request, message: VoiceMessage = None):
267
  if request.headers.get("origin") != "https://jofthomas-everchanging-quest.static.hf.space":
268
+ return 204
269
  global Last_message # Declare Last_message as global
270
  if message is None:
271
  message = Last_message
 
316
  @app.get("/generate_song")
317
  async def generate_song(request:SongRequest,httprequest: Request):
318
  if httprequest.headers.get("origin") != "https://jofthomas-everchanging-quest.static.hf.space":
319
+ return 204
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}"""
 
324
  song_lyrics=generate_lyrics({
325
  "prompt": f"{text}",
326
  })
327
+ if song_lyrics['text']:
328
+ data = custom_generate_audio({
329
+ "prompt": song_lyrics['text'],
330
+ "tags": "male bard",
331
+ "title":"Everchangin_Quest_song",
332
+ "wait_audio":True,
333
+
334
+ })
335
+ infos=get_audio_information(f"{data[0]['id']},{data[1]['id']}")
336
+ return infos
337
+ else:
338
+ return 204
339
 
340
  #@app.post('/generate_image')
341
  #def Imagen(image:ImageGen=None):