abdullahalioo commited on
Commit
1cb9532
·
verified ·
1 Parent(s): cc3751a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -19
main.py CHANGED
@@ -1,32 +1,22 @@
1
- from fastapi import FastAPI
2
- from pydantic import BaseModel
3
- from fastapi.middleware.cors import CORSMiddleware
4
- from fastapi.responses import StreamingResponse
5
  from hugchat import hugchat
6
  from hugchat.login import Login
7
- import asyncio
8
- import os
9
- from dotenv import load_dotenv
10
 
11
- # Load environment variables from .env file
12
- load_dotenv()
13
-
14
- # Read credentials from environment variables
15
  EMAIL = os.getenv("EMAIL")
16
  PASSWD = os.getenv("PASSWD")
17
- # Cookie storage
18
- cookie_path_dir = "./cookies/"
19
- os.makedirs(cookie_path_dir, exist_ok=True)
20
 
21
- # HugChat login
 
 
 
22
  sign = Login(EMAIL, PASSWD)
23
  cookies = sign.login(cookie_dir_path=cookie_path_dir, save_cookies=True)
24
 
25
- # Create chatbot instance
26
  chatbot = hugchat.ChatBot(cookies=cookies.get_dict())
27
 
28
- # Optional: Use assistant ID
29
- ASSISTANT_ID = "66017fca58d60bd7d5c5c26c" # Replace if needed
30
  chatbot.new_conversation(assistant=ASSISTANT_ID, switch_to=True)
31
 
32
  # 🔁 Stream response character-by-character as it generates
@@ -37,4 +27,3 @@ for token in chatbot.chat("Hello, how can I help you today?", stream=True):
37
  # Optionally: web search example
38
  # response = chatbot.chat("How many models stored in huggingface?", web_search=True)
39
  # print("\n\nWeb Search Result:", response.wait_until_done())
40
-
 
 
 
 
 
1
  from hugchat import hugchat
2
  from hugchat.login import Login
 
 
 
3
 
4
+ # Credentials
 
 
 
5
  EMAIL = os.getenv("EMAIL")
6
  PASSWD = os.getenv("PASSWD")
 
 
 
7
 
8
+ # Path to store cookies
9
+ cookie_path_dir = "./cookies/" # Make sure this directory exists
10
+
11
+ # Log in and get cookies
12
  sign = Login(EMAIL, PASSWD)
13
  cookies = sign.login(cookie_dir_path=cookie_path_dir, save_cookies=True)
14
 
15
+ # Create ChatBot with cookies
16
  chatbot = hugchat.ChatBot(cookies=cookies.get_dict())
17
 
18
+ # 🔁 Create a new conversation with a custom assistant ID
19
+ ASSISTANT_ID = "66017fca58d60bd7d5c5c26c" # Replace with your actual assistant ID
20
  chatbot.new_conversation(assistant=ASSISTANT_ID, switch_to=True)
21
 
22
  # 🔁 Stream response character-by-character as it generates
 
27
  # Optionally: web search example
28
  # response = chatbot.chat("How many models stored in huggingface?", web_search=True)
29
  # print("\n\nWeb Search Result:", response.wait_until_done())