gustavoaq commited on
Commit
b8e4ce9
1 Parent(s): de2c662

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -4,10 +4,12 @@ import torch
4
  from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
5
  from peft import PeftModel, PeftConfig
6
 
 
7
  MODEL_NAME = "IlyaGusev/llama_7b_ru_turbo_alpaca_lora"
8
-
9
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
10
  config = PeftConfig.from_pretrained(MODEL_NAME)
 
 
11
  model = AutoModelForCausalLM.from_pretrained(
12
  config.base_model_name_or_path,
13
  load_in_8bit=True,
@@ -16,13 +18,13 @@ model = AutoModelForCausalLM.from_pretrained(
16
  model = PeftModel.from_pretrained(model, MODEL_NAME)
17
  model.eval()
18
 
19
-
20
  def generate_prompt(instruction, input=None):
21
  if input:
22
- return f"Задание: {instruction}\nВход: {input}\nОтвет:"
23
- return f"Задание: {instruction}\n\nОтвет:"
24
-
25
 
 
26
  def evaluate(
27
  instruction,
28
  input=None,
@@ -55,14 +57,14 @@ def evaluate(
55
  output = tokenizer.decode(s, skip_special_tokens=True)
56
  return output.strip()
57
 
58
-
59
  g = gr.Interface(
60
  fn=evaluate,
61
  inputs=[
62
  gr.components.Textbox(
63
- lines=2, label="Задание", placeholder="Почему трава зеленая?"
64
  ),
65
- gr.components.Textbox(lines=2, label="Вход", placeholder="Нет"),
66
  gr.components.Slider(minimum=0, maximum=2, value=1.0, label="Temperature"),
67
  gr.components.Slider(minimum=0, maximum=1, value=0.8, label="Top p"),
68
  gr.components.Slider(minimum=0, maximum=100, value=40, label="Top k"),
@@ -80,5 +82,7 @@ g = gr.Interface(
80
  title="LLaMA 7B Ru Turbo Alpaca",
81
  description="",
82
  )
 
 
83
  g.queue(concurrency_count=1)
84
- g.launch()
 
4
  from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
5
  from peft import PeftModel, PeftConfig
6
 
7
+ # Set the model name and load the tokenizer and configuration for the model
8
  MODEL_NAME = "IlyaGusev/llama_7b_ru_turbo_alpaca_lora"
 
9
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
10
  config = PeftConfig.from_pretrained(MODEL_NAME)
11
+
12
+ # Load the model and set it to evaluation mode
13
  model = AutoModelForCausalLM.from_pretrained(
14
  config.base_model_name_or_path,
15
  load_in_8bit=True,
 
18
  model = PeftModel.from_pretrained(model, MODEL_NAME)
19
  model.eval()
20
 
21
+ # Define a function to generate a prompt based on the user's input
22
  def generate_prompt(instruction, input=None):
23
  if input:
24
+ return f"Task: {instruction}\nInput: {input}\nOutput:"
25
+ return f"Task: {instruction}\n\nOutput:"
 
26
 
27
+ # Define a function to evaluate the user's input and generate text based on it
28
  def evaluate(
29
  instruction,
30
  input=None,
 
57
  output = tokenizer.decode(s, skip_special_tokens=True)
58
  return output.strip()
59
 
60
+ # Set up a Gradio interface for the evaluation function
61
  g = gr.Interface(
62
  fn=evaluate,
63
  inputs=[
64
  gr.components.Textbox(
65
+ lines=2, label="Task", placeholder="Why is grass green?"
66
  ),
67
+ gr.components.Textbox(lines=2, label="Input", placeholder="None"),
68
  gr.components.Slider(minimum=0, maximum=2, value=1.0, label="Temperature"),
69
  gr.components.Slider(minimum=0, maximum=1, value=0.8, label="Top p"),
70
  gr.components.Slider(minimum=0, maximum=100, value=40, label="Top k"),
 
82
  title="LLaMA 7B Ru Turbo Alpaca",
83
  description="",
84
  )
85
+
86
+ # Queue the Gradio interface and launch it
87
  g.queue(concurrency_count=1)
88
+ g.launch()