Sameer-Handsome173 commited on
Commit
b85067b
Β·
verified Β·
1 Parent(s): a38e6cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -8
app.py CHANGED
@@ -4,12 +4,6 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
4
  import torch
5
  from typing import Optional
6
 
7
- # 🧩 LangSmith Integration (Optional)
8
- os.environ["LANGCHAIN_TRACING_V2"] = "true"
9
- os.environ["LANGCHAIN_PROJECT"] = "Qwen_4B_Chatbot"
10
- os.environ["LANGCHAIN_API_KEY"] = "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"
11
-
12
-
13
  app = FastAPI(title="πŸ€– Qwen 4B AI Chatbot")
14
 
15
  # βœ… Set writable cache directory
@@ -26,7 +20,7 @@ tokenizer = AutoTokenizer.from_pretrained(
26
 
27
  model = AutoModelForCausalLM.from_pretrained(
28
  model_name,
29
- torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
30
  device_map="auto",
31
  trust_remote_code=True
32
  )
@@ -109,7 +103,6 @@ def home():
109
  }
110
 
111
  @app.post("/chat")
112
- @traceable
113
  async def chat(
114
  query: str = Form(...),
115
  max_tokens: int = Form(512),
@@ -128,6 +121,7 @@ async def chat(
128
  - "Calculate 15% of 2500 and explain compound interest"
129
  - "Search for the latest AI news and summarize the top 3 trends"
130
  - "Write Python code to sort a list and explain how it works"
 
131
  """
132
  try:
133
  if not query or len(query.strip()) == 0:
 
4
  import torch
5
  from typing import Optional
6
 
 
 
 
 
 
 
7
  app = FastAPI(title="πŸ€– Qwen 4B AI Chatbot")
8
 
9
  # βœ… Set writable cache directory
 
20
 
21
  model = AutoModelForCausalLM.from_pretrained(
22
  model_name,
23
+ dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
24
  device_map="auto",
25
  trust_remote_code=True
26
  )
 
103
  }
104
 
105
  @app.post("/chat")
 
106
  async def chat(
107
  query: str = Form(...),
108
  max_tokens: int = Form(512),
 
121
  - "Calculate 15% of 2500 and explain compound interest"
122
  - "Search for the latest AI news and summarize the top 3 trends"
123
  - "Write Python code to sort a list and explain how it works"
124
+ - "What's the population of Belarus and its GDP?"
125
  """
126
  try:
127
  if not query or len(query.strip()) == 0: