Spaces:
Paused
Paused
Update app.py
Browse files338 unmodified lines33934034134234334434534634 unmodified lines381382383384385386387166 unmodified lines554555556557558559560561562563564565566567568569570571572573574575576577338 unmodified lines@app.get("/api/adv_web_search")async def adv_web_search(q: str,model: str = "llama3-8b",max_results: int = 3,timelimit: Optional[str] = None,safesearch: str = "moderate",region: str = "wt-wt",34 unmodified lines# 4. Get the FastAI's response using FastAI servicetry:response = await asyncio.to_thread(fastai, ai_prompt, model=model, system=system_prompt)except Exception as e:raise HTTPException(status_code=500, detail=f"Error during FastAI request: {e}")166 unmodified linesimport uvicornuvicorn.run(app, host="0.0.0.0", port=8083)def main():# Retrieve the space ID and token from environment variablesspace_id = os.getenv("SPACE_ID")token = os.getenv("HF_TOKEN")# Initialize the HfApi with the retrieved tokenapi = HfApi(token=token)while True:try:# Restart the spaceapi.restart_space(space_id, factory_reboot=False)print(f"Successfully restarted the space: {space_id}")except Exception as e:print(f"Error restarting the space: {e}")# Wait for 10 minutes before restarting againtime.sleep(600) # Sleep for 600 seconds (10 minutes)if __name__ == "__main__":main()338 unmodified lines33934034134234334434534634 unmodified lines381382383384385386387166 unmodified lines554555556557558559560561562563564565566567568569570571572573574575576577338 unmodified lines@app.get("/api/adv_web_search")async def adv_web_search(q: str,model: str = "gpt-4o-mini",max_results: int = 5,timelimit: Optional[str] = None,safesearch: str = "moderate",region: str = "wt-wt",34 unmodified lines# 4. Get the FastAI's response using FastAI servicetry:response = webs.chat(keywords=ai_prompt, model=model)except Exception as e:raise HTTPException(status_code=500, detail=f"Error during FastAI request: {e}")166 unmodified linesimport uvicornuvicorn.run(app, host="0.0.0.0", port=8083)# def main():# # Retrieve the space ID and token from environment variables# space_id = os.getenv("SPACE_ID")# token = os.getenv("HF_TOKEN")# # Initialize the HfApi with the retrieved token# api = HfApi(token=token)# while True:# try:# # Restart the space# api.restart_space(space_id, factory_reboot=False)# print(f"Successfully restarted the space: {space_id}")# except Exception as e:# print(f"Error restarting the space: {e}")# # Wait for 10 minutes before restarting again# time.sleep(600) # Sleep for 600 seconds (10 minutes)# if __name__ == "__main__":# main()
app.py+20-20