Views
No views yet
1import logging
2from simpletransformers.seq2seq import Seq2SeqModel, Seq2SeqArgs
3
4logging.basicConfig(level=logging.INFO)
5transformers_logger = logging.getLogger("transformers")
6transformers_logger.setLevel(logging.WARNING)
7
8model_args = Seq2SeqArgs()
9
10# 加载本地训练好的模型
11model = Seq2SeqModel(
12 encoder_decoder_type="bart",
13 encoder_decoder_name="NTUYG/SOTitle-java-BART",
14 args=model_args,
15)
16
17describe = """
18I am a beginner at Android Java development but I have a few years of school + uni experience in Java. I am trying to write to a text file in an assets folder in my app using FileOutputStream but it doesn't seem to write to it at all since I am using InputStream to read the file after and there haven't any updates. Here is my code
19"""
20code = """
21private void updateTextFile(String update) {
22 FileOutputStream fos = null;
23
24 try
25 {
26 fos = openFileOutput("Questions",MODE_PRIVATE);
27 fos.write("Testing".getBytes());
28 }
29 catch (FileNotFoundException e)
30 {
31 e.printStackTrace();
32 }
33 catch (IOException e)
34 {
35 e.printStackTrace();
36 }
37 finally
38 {
39 if(fos!=null)
40 {
41 try
42 {
43 fos.close();
44 }
45 catch (IOException e)
46 {
47 e.printStackTrace();
48 }
49 }
50 }
51
52 String text = "";
53
54 try
55 {
56 InputStream is = getAssets().open("Questions");
57 int size = is.available();
58 byte[] buffer = new byte[size];
59 is.read(buffer);
60 is.close();
61 text = new String(buffer);
62 }
63 catch (IOException e)
64 {
65 e.printStackTrace();
66 }
67 System.out.println("Tesing output " + text);
68}
69"""
70
71from nltk import word_tokenize
72
73describe = describe.replace('\n',' ').replace('\r',' ')
74describe = ' '.join(word_tokenize(describe))
75code = code.replace('\n',' ').replace('\r',' ')
76code = ' '.join(word_tokenize(code))
77
78# human : Java Android Cant seem to update text file using FileOutputStream
79
80body = describe + ' <code> ' + code +' </code>'
81print(
82 model.predict(
83 [
84 body
85 ]
86 )
87)