from hugchat import hugchat from hugchat.login import Login import fastapi from fastapi import FastAPI, Query app = FastAPI() # Your HuggingFace credentials EMAIL = "abdullahali1692011@gmail.com" PASSWORD = "Allahisgreatest17" @app.post("/ask") def main(prompt: str = Query(..., description="The prompt for the AI")): # Login and save cookies (optional cookie path omitted for simplicity) sign = Login(EMAIL, PASSWORD) cookies = sign.login(save_cookies=True) # Initialize chatbot with cookies chatbot = hugchat.ChatBot(cookies=cookies.get_dict()) # Start a new conversation with your assistant ID ASSISTANT_ID = "682e0c1f5f0c3d952a27498e" # Replace with your assistant ID chatbot.new_conversation(assistant=ASSISTANT_ID, switch_to=True) # Send message and get the full response (no streaming) response = chatbot.chat(f"{prompt}", stream=False) # Print full response print("Assistant:", response) return response