Kjgarza commited on
Commit
feafd16
1 Parent(s): 243160e
Files changed (3) hide show
  1. app.py +1 -1
  2. metadata_transformer.py +21 -26
  3. requirements.txt +1 -3
app.py CHANGED
@@ -34,7 +34,7 @@ interface = gr.Interface(
34
  fn=metadata_transformer.translate, # This function will handle the logic and transformations.
35
  inputs=inputs,
36
  outputs="text",
37
- # live=True,
38
  title="Schema Transformer with Llama2",
39
  description="Paste your schema, specify the target, and get the transformed schema."
40
  )
 
34
  fn=metadata_transformer.translate, # This function will handle the logic and transformations.
35
  inputs=inputs,
36
  outputs="text",
37
+ live=True,
38
  title="Schema Transformer with Llama2",
39
  description="Paste your schema, specify the target, and get the transformed schema."
40
  )
metadata_transformer.py CHANGED
@@ -1,34 +1,29 @@
1
- from transformers import pipeline
2
- from transformers import AutoTokenizer
3
- import torch
4
  import os
5
  from huggingface_hub import login
 
 
6
 
7
  TOKEN = os.environ.get("TOKEN")
8
 
9
  login(token=TOKEN)
10
 
11
- def translate(schema_input, schema_target):
12
-
13
-
14
- model = "meta-llama/Llama-2-7b-chat-hf"
15
-
16
- tokenizer = AutoTokenizer.from_pretrained(model)
17
- pipe = pipeline(
18
- "text-generation",
19
- model=model,
20
- torch_dtype=torch.float16,
21
- device_map="auto",
 
 
 
 
 
 
 
22
  )
23
-
24
- sequences = pipe(
25
- '{} \n Translate the schema metadata file above to the schema: {}'.format(schema_input, schema_target),
26
- do_sample=True,
27
- top_k=10,
28
- num_return_sequences=1,
29
- eos_token_id=tokenizer.eos_token_id,
30
- max_length=200,
31
- )
32
- return sequences[0]['generated_text']
33
-
34
-
 
 
 
 
1
  import os
2
  from huggingface_hub import login
3
+ from easyllm.clients import huggingface
4
+ from easyllm.prompt_utils import build_llama2_prompt
5
 
6
  TOKEN = os.environ.get("TOKEN")
7
 
8
  login(token=TOKEN)
9
 
10
+ huggingface.prompt_builder = build_llama2_prompt
11
+
12
+ system_message = """
13
+ You are a metadata schema translator. You translate metadata from one schema to another.
14
+ """
15
+
16
+ def translate(inputs):
17
+ schema_input, schema_target = inputs
18
+ propmpt = '{} \n Translate the schema metadata file above to the schema: {}'.format(schema_input, schema_target),
19
+ response = huggingface.ChatCompletion.create(
20
+ model="meta-llama/Llama-2-70b-chat-hf",
21
+ messages=[
22
+ {"role": "system", "content": system_message},
23
+ {"role": "user", "content": propmpt},
24
+ ],
25
+ temperature=0.9,
26
+ top_p=0.6,
27
+ max_tokens=256,
28
  )
29
+ return response['choices'][0]['message']['content']
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,3 +1 @@
1
- torch==2.0.0
2
- transformers==4.34.0
3
- accelerate
 
1
+ easyllm