TeePoat commited on
Commit
800d8cf
·
verified ·
1 Parent(s): 9dba108

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -1,9 +1,11 @@
1
- import gradio as gr
2
  import spaces
 
 
3
  from transformers import AutoTokenizer, AutoModelForCausalLM
4
- from peft import LoraConfig, get_peft_model
5
 
6
 
 
7
  SYSTEM_PROMPT = """Тебя зовут "Безумный Лис".. Ты участник дружеского чата с неформальным общением. Твоя задача — подобрать резкое, безумное ответное сообщение на основе предоставленного диалога.
8
 
9
  ПРАВИЛА ОТВЕТА
@@ -21,19 +23,17 @@ SYSTEM_PROMPT = """Тебя зовут "Безумный Лис".. Ты учас
21
  """
22
 
23
  tokenizer = AutoTokenizer.from_pretrained("RefalMachine/RuadaptQwen3-4B-Instruct")
24
- model = AutoModelForCausalLM.from_pretrained("RefalMachine/RuadaptQwen3-4B-Instruct", device_map="auto")
25
 
26
- lora_config = LoraConfig(
27
- r=16,
28
- lora_alpha=16,
29
- target_modules=["q_proj", "v_proj"],
30
- lora_dropout=0.05,
31
- bias="none",
32
- task_type="CAUSAL_LM",
33
  )
34
 
 
35
  @spaces.GPU
36
- def greet(content, intensity):
37
  messages = [
38
  {
39
  "role": "system", "content": SYSTEM_PROMPT,
@@ -52,6 +52,7 @@ def greet(content, intensity):
52
  **inputs,
53
  max_new_tokens=400,
54
  temperature=0.83,
 
55
  )
56
 
57
  return tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
@@ -59,9 +60,9 @@ def greet(content, intensity):
59
 
60
  demo = gr.Interface(
61
  fn=greet,
62
- inputs=["text", "slider"],
63
  outputs=["text"],
64
- api_name="predict"
65
  )
66
 
67
  if __name__ == "__main__":
 
1
+ import os
2
  import spaces
3
+ import gradio as gr
4
+ from peft import LoraConfig, get_peft_model, PeftModel
5
  from transformers import AutoTokenizer, AutoModelForCausalLM
 
6
 
7
 
8
+ APP_DIR = os.path.dirname(os.path.abspath(__file__))
9
  SYSTEM_PROMPT = """Тебя зовут "Безумный Лис".. Ты участник дружеского чата с неформальным общением. Твоя задача — подобрать резкое, безумное ответное сообщение на основе предоставленного диалога.
10
 
11
  ПРАВИЛА ОТВЕТА
 
23
  """
24
 
25
  tokenizer = AutoTokenizer.from_pretrained("RefalMachine/RuadaptQwen3-4B-Instruct")
26
+ base_model = AutoModelForCausalLM.from_pretrained("RefalMachine/RuadaptQwen3-4B-Instruct", device_map="auto")
27
 
28
+
29
+ peft_model = PeftModel.from_pretrained(
30
+ base_model,
31
+ os.path.join(APP_DIR, "models", "frantics-fox-lora-adapter")
 
 
 
32
  )
33
 
34
+
35
  @spaces.GPU
36
+ def generate(content):
37
  messages = [
38
  {
39
  "role": "system", "content": SYSTEM_PROMPT,
 
52
  **inputs,
53
  max_new_tokens=400,
54
  temperature=0.83,
55
+ repetition_penalty=1.15,
56
  )
57
 
58
  return tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
 
60
 
61
  demo = gr.Interface(
62
  fn=greet,
63
+ inputs=["text"],
64
  outputs=["text"],
65
+ api_name="generate"
66
  )
67
 
68
  if __name__ == "__main__":