cutechicken commited on
Commit
1c47184
1 Parent(s): 4c2534c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -5,14 +5,14 @@ import pandas as pd
5
  import json
6
  from datetime import datetime
7
  import torch
8
- from transformers import AutoTokenizer, AutoModelForCausalLM
 
 
9
 
10
  # 환경 변수 설정
11
  HF_TOKEN = os.getenv("HF_TOKEN")
12
  MODEL_ID = "CohereForAI/c4ai-command-r7b-12-2024"
13
 
14
- import spaces
15
-
16
  class ModelManager:
17
  def __init__(self):
18
  self.tokenizer = None
@@ -142,9 +142,6 @@ class ChatHistory:
142
  chat_history = ChatHistory()
143
  model_manager = ModelManager()
144
 
145
- def get_client():
146
- return InferenceClient(MODEL_ID, token=HF_TOKEN)
147
-
148
  def analyze_file_content(content, file_type):
149
  """Analyze file content and return structural summary"""
150
  if file_type in ['parquet', 'csv']:
@@ -262,17 +259,15 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
262
 
263
  messages.append({"role": "user", "content": message})
264
 
265
- client = get_client()
266
  partial_message = ""
267
 
268
- for msg in client.chat_completion(
269
  messages,
270
  max_tokens=max_tokens,
271
- stream=True,
272
  temperature=temperature,
273
- top_p=top_p,
274
  ):
275
- token = msg.choices[0].delta.get('content', None)
276
  if token:
277
  partial_message += token
278
  current_history = history + [[message, partial_message]]
 
5
  import json
6
  from datetime import datetime
7
  import torch
8
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
9
+ import spaces
10
+ from threading import Thread
11
 
12
  # 환경 변수 설정
13
  HF_TOKEN = os.getenv("HF_TOKEN")
14
  MODEL_ID = "CohereForAI/c4ai-command-r7b-12-2024"
15
 
 
 
16
  class ModelManager:
17
  def __init__(self):
18
  self.tokenizer = None
 
142
  chat_history = ChatHistory()
143
  model_manager = ModelManager()
144
 
 
 
 
145
  def analyze_file_content(content, file_type):
146
  """Analyze file content and return structural summary"""
147
  if file_type in ['parquet', 'csv']:
 
259
 
260
  messages.append({"role": "user", "content": message})
261
 
 
262
  partial_message = ""
263
 
264
+ for response in model_manager.generate_response(
265
  messages,
266
  max_tokens=max_tokens,
 
267
  temperature=temperature,
268
+ top_p=top_p
269
  ):
270
+ token = response.choices[0].delta.get('content', '')
271
  if token:
272
  partial_message += token
273
  current_history = history + [[message, partial_message]]