Leri777 commited on
Commit
a4b2221
1 Parent(s): c9d6a44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -15
app.py CHANGED
@@ -1,20 +1,15 @@
1
  import os
2
- import json
3
- import subprocess
4
- from threading import Thread
5
  import logging
6
  from logging.handlers import RotatingFileHandler
7
 
8
  import torch
9
- import spaces
10
  import gradio as gr
11
- from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TextIteratorStreamer
12
  from langchain_huggingface import ChatHuggingFace
13
  from langchain.prompts import PromptTemplate
14
  from langchain.chains import LLMChain
15
 
16
- subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
17
-
18
  log_file = '/tmp/app_debug.log'
19
  logger = logging.getLogger(__name__)
20
  logger.setLevel(logging.DEBUG)
@@ -47,14 +42,12 @@ template = """<|im_start|>system
47
  """
48
  prompt = PromptTemplate(template=template, input_variables=["system_prompt", "history", "human_input"])
49
 
50
- # Format the conversation history
51
  def format_history(history):
52
  formatted = ""
53
  for human, ai in history:
54
  formatted += f"<|im_start|>user\n{human}\n<|im_end|>\n<|im_start|>assistant\n{ai}\n<|im_end|>\n"
55
  return formatted
56
 
57
- @spaces.GPU()
58
  def predict(message, history, system_prompt, temperature, max_new_tokens, top_k, repetition_penalty, top_p):
59
  logger.debug(f"Received prediction request: message='{message}', system_prompt='{system_prompt}'")
60
 
@@ -88,7 +81,6 @@ chat_model = ChatHuggingFace(
88
  model_kwargs={
89
  "device_map": "auto",
90
  "quantization_config": quantization_config,
91
- "attn_implementation": "flash_attention_2",
92
  },
93
  tokenizer=tokenizer
94
  )
@@ -105,11 +97,6 @@ gr.ChatInterface(
105
  ["How can I reverse a string in JavaScript?"],
106
  ["Create a C++ function to find the factorial of a number."],
107
  ["Write a Python list comprehension to generate a list of squares of numbers from 1 to 10."],
108
- ["How do I implement a binary search algorithm in C?"],
109
- ["Write a Ruby script to read a file and count the number of lines in it."],
110
- ["Create a Swift class to represent a bank account with deposit and withdrawal methods."],
111
- ["How do I find the maximum element in an array using Kotlin?"],
112
- ["Write a Rust program to generate the Fibonacci sequence up to the 10th number."]
113
  ],
114
  additional_inputs=[
115
  gr.Textbox("You are a code assistant.", label="System prompt"),
 
1
  import os
 
 
 
2
  import logging
3
  from logging.handlers import RotatingFileHandler
4
 
5
  import torch
 
6
  import gradio as gr
7
+ from transformers import AutoTokenizer, BitsAndBytesConfig
8
  from langchain_huggingface import ChatHuggingFace
9
  from langchain.prompts import PromptTemplate
10
  from langchain.chains import LLMChain
11
 
12
+ # Настройка логирования
 
13
  log_file = '/tmp/app_debug.log'
14
  logger = logging.getLogger(__name__)
15
  logger.setLevel(logging.DEBUG)
 
42
  """
43
  prompt = PromptTemplate(template=template, input_variables=["system_prompt", "history", "human_input"])
44
 
 
45
  def format_history(history):
46
  formatted = ""
47
  for human, ai in history:
48
  formatted += f"<|im_start|>user\n{human}\n<|im_end|>\n<|im_start|>assistant\n{ai}\n<|im_end|>\n"
49
  return formatted
50
 
 
51
  def predict(message, history, system_prompt, temperature, max_new_tokens, top_k, repetition_penalty, top_p):
52
  logger.debug(f"Received prediction request: message='{message}', system_prompt='{system_prompt}'")
53
 
 
81
  model_kwargs={
82
  "device_map": "auto",
83
  "quantization_config": quantization_config,
 
84
  },
85
  tokenizer=tokenizer
86
  )
 
97
  ["How can I reverse a string in JavaScript?"],
98
  ["Create a C++ function to find the factorial of a number."],
99
  ["Write a Python list comprehension to generate a list of squares of numbers from 1 to 10."],
 
 
 
 
 
100
  ],
101
  additional_inputs=[
102
  gr.Textbox("You are a code assistant.", label="System prompt"),