Timaska commited on
Commit
3d09fd3
·
verified ·
1 Parent(s): 7c902f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -1,24 +1,26 @@
1
  import gradio as gr
 
2
  from huggingface_hub import InferenceClient
3
 
4
- # Укажи свою модель автодополнения кода (можно заменить на другую)
 
 
 
5
  client = InferenceClient(
6
- model="deepseek-ai/deepseek-coder-1.3b-base", # или starcoder2, codegemma, etc.
7
- token=HF_TOKKEN # или укажи свой токен явно: token="hf_xxxxxxxxxxxxxxxxx"
8
  )
9
 
10
- # Функция генерации кода с потоковым выводом
11
  def complete_code(prompt, max_tokens, temperature, top_p):
12
- response = ""
13
- for token in client.text_generation(
14
  prompt,
15
  max_new_tokens=max_tokens,
16
  temperature=temperature,
17
  top_p=top_p,
18
- stream=True,
19
- ):
20
- response += token # token — это уже str
21
- yield response
22
 
23
  # Интерфейс Gradio
24
  demo = gr.Interface(
 
1
  import gradio as gr
2
+ import os
3
  from huggingface_hub import InferenceClient
4
 
5
+ # Получаем токен из переменной окружения
6
+ HF_TOKEN = os.getenv("HF_TOKEN")
7
+
8
+ # Клиент Hugging Face для выбранной модели
9
  client = InferenceClient(
10
+ model="deepseek-ai/deepseek-coder-1.3b-base", # Можешь заменить на starcoder2 или codegemma
11
+ token=HF_TOKEN
12
  )
13
 
14
+ # Функция генерации без stream (deepseek не поддерживает stream=True)
15
  def complete_code(prompt, max_tokens, temperature, top_p):
16
+ response = client.text_generation(
 
17
  prompt,
18
  max_new_tokens=max_tokens,
19
  temperature=temperature,
20
  top_p=top_p,
21
+ stream=False # ⚠️ обязательно False для этой модели
22
+ )
23
+ return response
 
24
 
25
  # Интерфейс Gradio
26
  demo = gr.Interface(