lhoestq HF staff commited on
Commit
8f3ed37
1 Parent(s): 05ecaec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -68,17 +68,16 @@ demo = gr.ChatInterface(
68
  app = FastAPI()
69
 
70
  @app.head("/ask")
71
- def chat_head():
72
  return StreamingResponse("", media_type="application/json")
73
 
74
  @app.get("/ask")
75
- def chat_get(message: str = "", system_message: str = "You are a friendly Chatbot.", max_tokens: int = 512, temperature: float = 0.7, top_p: float = 0.95):
76
  predict_response = requests.post('http://localhost:7860/call/chat', json={'data': [message, [], system_message, max_tokens, temperature, top_p]}).json()
77
  if "event_id" not in predict_response:
78
  return predict_response
79
  out = requests.get(f'http://localhost:7860/call/chat/{predict_response["event_id"]}').text
80
- print(out)
81
- return JSONResponse([json.loads(out.rsplit("event: generating\ndata: ", 1)[-1].strip())[0].strip()])
82
 
83
  if __name__ == "__main__":
84
  app = gr.mount_gradio_app(app, demo, path="/")
 
68
  app = FastAPI()
69
 
70
  @app.head("/ask")
71
+ def ask_head():
72
  return StreamingResponse("", media_type="application/json")
73
 
74
  @app.get("/ask")
75
+ def ask_get(message: str = "", system_message: str = "You are a friendly Chatbot.", max_tokens: int = 512, temperature: float = 0.7, top_p: float = 0.95):
76
  predict_response = requests.post('http://localhost:7860/call/chat', json={'data': [message, [], system_message, max_tokens, temperature, top_p]}).json()
77
  if "event_id" not in predict_response:
78
  return predict_response
79
  out = requests.get(f'http://localhost:7860/call/chat/{predict_response["event_id"]}').text
80
+ return JSONResponse([json.loads(out.rsplit("event: complete\ndata: ", 1)[-1])[0].strip()])
 
81
 
82
  if __name__ == "__main__":
83
  app = gr.mount_gradio_app(app, demo, path="/")