RinInori commited on
Commit
ac7945c
1 Parent(s): f87f02c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -34
app.py CHANGED
@@ -55,30 +55,14 @@ else:
55
  device_map={"": device},
56
  )
57
 
58
- def generate_prompt(instruction, input=None):
59
- if input:
60
- return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
61
- ### Instruction:
62
- {instruction}
63
- ### Input:
64
- {input}
65
- ### Response:"""
66
- else:
67
- return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
68
- ### Instruction :
69
- {instruction}
70
- ### Response :"""
71
-
72
  if device != "cpu":
73
  model.half()
74
  model.eval()
75
  if torch.__version__ >= "2":
76
  model = torch.compile(model)
77
 
78
-
79
  def evaluate(
80
- instruction,
81
- input=None,
82
  temperature=0.1,
83
  top_p=0.75,
84
  top_k=40,
@@ -86,7 +70,7 @@ def evaluate(
86
  max_new_tokens=128,
87
  **kwargs,
88
  ):
89
- prompt = generate_prompt(instruction, input)
90
  inputs = tokenizer(prompt, return_tensors="pt")
91
  input_ids = inputs["input_ids"].to(device)
92
  generation_config = GenerationConfig(
@@ -106,27 +90,16 @@ def evaluate(
106
  )
107
  s = generation_output.sequences[0]
108
  output = tokenizer.decode(s)
109
- return output.split("### Response:")[1].strip()
110
 
111
  g = gr.Interface(
112
  fn=evaluate,
113
- inputs=[
114
- gr.inputs.Textbox(
115
- label="Instruction",
116
- placeholder="Type your instruction here...",
117
- lines=3
118
- ),
119
- gr.inputs.Textbox(
120
- label="Input",
121
- placeholder="Type additional input here...",
122
- lines=3
123
- ),
124
- ],
125
  outputs=gr.outputs.Textbox(label="Output"),
126
- title="Instruction-based Text Generation",
127
- description="Enter an instruction and optional input, and the model will generate a response based on the instruction.",
128
  theme="default",
129
  )
130
 
131
  if __name__ == "__main__":
132
- g.launch()
 
55
  device_map={"": device},
56
  )
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  if device != "cpu":
59
  model.half()
60
  model.eval()
61
  if torch.__version__ >= "2":
62
  model = torch.compile(model)
63
 
 
64
  def evaluate(
65
+ input_text,
 
66
  temperature=0.1,
67
  top_p=0.75,
68
  top_k=40,
 
70
  max_new_tokens=128,
71
  **kwargs,
72
  ):
73
+ prompt = input_text
74
  inputs = tokenizer(prompt, return_tensors="pt")
75
  input_ids = inputs["input_ids"].to(device)
76
  generation_config = GenerationConfig(
 
90
  )
91
  s = generation_output.sequences[0]
92
  output = tokenizer.decode(s)
93
+ return output.strip()
94
 
95
  g = gr.Interface(
96
  fn=evaluate,
97
+ inputs=gr.inputs.Textbox(label="Input", placeholder="Type your input here..."),
 
 
 
 
 
 
 
 
 
 
 
98
  outputs=gr.outputs.Textbox(label="Output"),
99
+ title="Text Generation",
100
+ description="Enter an input, and the model will generate a response based on the input.",
101
  theme="default",
102
  )
103
 
104
  if __name__ == "__main__":
105
+ g.launch()