EmicoBinsfinder commited on
Commit
c585a5d
·
1 Parent(s): c9d871b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -50
app.py CHANGED
@@ -9,10 +9,10 @@ from transformers import AutoTokenizer, AutoConfig, LlamaForCausalLM, LlamaToken
9
 
10
  auth_token = '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' #= os.environ.get("TOKEN_FROM_SECRET")
11
 
12
- tokenizer = LlamaTokenizer.from_pretrained("Claimed/capybara", use_auth_token=auth_token)
13
 
14
- model = LlamaForCausalLM.from_pretrained(
15
- "Claimed/capybara", use_auth_token=auth_token)
16
  #model = model.to('cuda')
17
 
18
 
@@ -76,53 +76,53 @@ def classifier(userin):
76
  return broad_scope_predictions[1]
77
 
78
 
79
- def generateresponse(history):
80
- """
81
- Model definition here:
82
- """
83
- '''
84
- global model
85
- global tokenizer
86
-
87
- PROMPT = f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
88
- ### Instruction:
89
- {user}
90
- ### Response:"""
91
-
92
- inputs = tokenizer(
93
- PROMPT,
94
- return_tensors="pt",
95
- )
96
- input_ids = inputs["input_ids"].cuda()
97
-
98
- generation_config = GenerationConfig(
99
- temperature=0.6,
100
- top_p=0.95,
101
- repetition_penalty=1.15,
102
- )
103
- print("Generating...")
104
- generation_output = model.generate(
105
- input_ids=input_ids,
106
- generation_config=generation_config,
107
- return_dict_in_generate=True,
108
- output_scores=True,
109
- max_new_tokens=256,
110
- )
111
- output = []
112
- for s in generation_output.sequences:
113
- outputs.append(tokenizer.decode(s))
114
- print(tokenizer.decode(s))
115
 
116
- output = (outputs[0].split('### Response:'))[1]
117
 
118
- '''
119
 
120
- user = history[-1][0]
121
 
122
- response = f"You asked: {user}"
123
- history[-1][1] = response
124
- print(history)
125
- return history
126
 
127
 
128
  theme = gr.themes.Base(
@@ -206,7 +206,7 @@ with gr.Blocks(title='Claimed', theme=theme) as demo:
206
 
207
  with gr.Tab("CPC Classifier"):
208
  gr.Markdown("""
209
- Use this tool to classify your invention according to Cooperative Patent Classification system.
210
 
211
  """)
212
  with gr.Row(scale=1, min_width=600):
@@ -240,9 +240,9 @@ with gr.Blocks(title='Claimed', theme=theme) as demo:
240
  with gr.Column(scale=0.15, min_width=0):
241
  btn = gr.Button("Submit")
242
 
243
- txt.submit(add_text, [chatbot, txt], [chatbot, txt]).then(
244
- generateresponse, chatbot, chatbot
245
- )
246
 
247
  gr.Markdown("""
248
  # HAVE AN IDEA? GET IT CLAIMED
 
9
 
10
  auth_token = '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' #= os.environ.get("TOKEN_FROM_SECRET")
11
 
12
+ # tokenizer = LlamaTokenizer.from_pretrained("Claimed/capybara", use_auth_token=auth_token)
13
 
14
+ # model = LlamaForCausalLM.from_pretrained(
15
+ # "Claimed/capybara", use_auth_token=auth_token)
16
  #model = model.to('cuda')
17
 
18
 
 
76
  return broad_scope_predictions[1]
77
 
78
 
79
+ # def generateresponse(history):
80
+ # """
81
+ # Model definition here:
82
+ # """
83
+ # '''
84
+ # global model
85
+ # global tokenizer
86
+
87
+ # PROMPT = f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
88
+ # ### Instruction:
89
+ # {user}
90
+ # ### Response:"""
91
+
92
+ # inputs = tokenizer(
93
+ # PROMPT,
94
+ # return_tensors="pt",
95
+ # )
96
+ # input_ids = inputs["input_ids"].cuda()
97
+
98
+ # generation_config = GenerationConfig(
99
+ # temperature=0.6,
100
+ # top_p=0.95,
101
+ # repetition_penalty=1.15,
102
+ # )
103
+ # print("Generating...")
104
+ # generation_output = model.generate(
105
+ # input_ids=input_ids,
106
+ # generation_config=generation_config,
107
+ # return_dict_in_generate=True,
108
+ # output_scores=True,
109
+ # max_new_tokens=256,
110
+ # )
111
+ # output = []
112
+ # for s in generation_output.sequences:
113
+ # outputs.append(tokenizer.decode(s))
114
+ # print(tokenizer.decode(s))
115
 
116
+ # output = (outputs[0].split('### Response:'))[1]
117
 
118
+ # '''
119
 
120
+ # user = history[-1][0]
121
 
122
+ # response = f"You asked: {user}"
123
+ # history[-1][1] = response
124
+ # print(history)
125
+ # return history
126
 
127
 
128
  theme = gr.themes.Base(
 
206
 
207
  with gr.Tab("CPC Classifier"):
208
  gr.Markdown("""
209
+ Use this tool to classify your invention according to the Cooperative Patent Classification system.
210
 
211
  """)
212
  with gr.Row(scale=1, min_width=600):
 
240
  with gr.Column(scale=0.15, min_width=0):
241
  btn = gr.Button("Submit")
242
 
243
+ # txt.submit(add_text, [chatbot, txt], [chatbot, txt]).then(
244
+ # generateresponse, chatbot, chatbot
245
+ # )
246
 
247
  gr.Markdown("""
248
  # HAVE AN IDEA? GET IT CLAIMED