Spaces:
Running
Running
Update tokenizer.py
Browse files- tokenizer.py +40 -55
tokenizer.py
CHANGED
@@ -1,56 +1,41 @@
|
|
|
|
1 |
from transformers import pipeline
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
]
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
"Model response: Modify the file found on the remote server",
|
42 |
-
"Model prompt: Completed the task: Modify the file found on the remote server Progress: Connect to the remote server using the SSH protocol\nSearch for a file on the remote server\nModify the file found on the remote server",
|
43 |
-
"Model response: You have successfully completed the task: Modify the file found on the remote server",
|
44 |
-
"Model prompt: Updated the task description to 'Verify the file modifications using the updated file'",
|
45 |
-
"Model response: Verify the file modifications using the updated file",
|
46 |
-
"Model prompt: Completed the task: Verify the file modifications using the updated file Progress: Connect to the remote server using the SSH protocol\nSearch for a file on the remote server\nModify the file found on the remote server\nVerify the file modifications using the updated file",
|
47 |
-
"Model response: You have successfully completed the task: Verify the file modifications using the updated file",
|
48 |
-
"Model prompt: Updated the task description to 'Create a summary of the timeline of progress and any important challenges faced during the development of the app'",
|
49 |
-
"Model response: Create a summary of the timeline of progress and any important challenges faced during the development of the app",
|
50 |
-
"Model prompt: Completed the task: Create a summary of the timeline of progress and any important challenges faced.",
|
51 |
-
"Model response: All tasks complete. What shall I do next?"
|
52 |
-
]
|
53 |
-
}
|
54 |
-
|
55 |
-
code = generator(input_text, max_length=50, num_return_sequences=1, do_sample=True)[0]['generated_text']
|
56 |
-
return code
|
|
|
1 |
+
import os
|
2 |
from transformers import pipeline
|
3 |
+
|
4 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
5 |
+
|
6 |
+
class CodeGenerator:
|
7 |
+
def __init__(self, model_name='bigscience/T0_3B'):
|
8 |
+
self.generator = pipeline('text-generation', model=model_name)
|
9 |
+
|
10 |
+
def generate_code(self, task_description):
|
11 |
+
"""
|
12 |
+
Generates code based on the provided task description using the specified language model.
|
13 |
+
|
14 |
+
Parameters:
|
15 |
+
task_description (str): The task description or prompt for generating the code.
|
16 |
+
|
17 |
+
Returns:
|
18 |
+
str: The generated code.
|
19 |
+
"""
|
20 |
+
return self._generate_code_from_model(task_description)
|
21 |
+
|
22 |
+
def _generate_code_from_model(self, input_text):
|
23 |
+
"""
|
24 |
+
Internal method to generate code from the model.
|
25 |
+
|
26 |
+
Parameters:
|
27 |
+
input_text (str): The input text for code generation.
|
28 |
+
|
29 |
+
Returns:
|
30 |
+
str: The code generated by the language model.
|
31 |
+
"""
|
32 |
+
return self.generator(input_text, max_length=50, num_return_sequences=1, do_sample=True)[0]['generated_text']
|
33 |
+
|
34 |
+
def main():
|
35 |
+
task_description = "Develop an app that allows users to search for and modify files on a remote server using the SSH protocol"
|
36 |
+
code_generator = CodeGenerator()
|
37 |
+
generated_code = code_generator.generate_code(task_description)
|
38 |
+
print(generated_code)
|
39 |
+
|
40 |
+
if __name__ == "__main__":
|
41 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|