Method for doing seven-statement clause poem based on python artificial intelligence
By automatically generating seven-character quatrains using a Python artificial intelligence system, the problem of low speed and efficiency in traditional manual creation has been solved, and efficient and diverse poem generation has been achieved.
Patent Information
- Application Number
- CN202410619914.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-20
- Publication Date
- 2024-08-27
AI Technical Summary
Traditional manual creation of seven-character quatrains is not fast or efficient enough, and poets' creation is limited by their own skills and styles, resulting in monotonous, undiverse and shallow poems.
It employs a Python-based artificial intelligence system, combining an intelligent automatic poetry generation module, a Baidu AI Cloud module, and an Excel module. Through keyword verification, prompts, authentication, and optimization, it generates seven-character quatrains and uses the Baidu Wenxin Yiyan API interface for automatic poetry generation.
It lowered the threshold for creation, shortened the creation cycle, increased the diversity and speed of creation of verses, and enhanced the innovation and diversity of verses.
Smart Images

Figure CN118550992A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of literary poetry, and in particular to a method for making seven-character quatrain poems based on Python artificial intelligence. Background Art
[0002] Poetry refers to the traditional Chinese poetry represented by ancient poetry, modern poetry and rhythmic poetry, and is also one of the characteristics of the Chinese character cultural circle. Poetry is a literary art that expounds the soul, and poets and lyricists need to master mature artistic skills and use concise language, dense composition, abundant emotions and rich images to highly concentrate on expressing social life and the human spiritual world in accordance with strict rhythm requirements. There are many types of poetry, among which the seven-character quatrain is one of the most widely spread forms of poetry. Poetry mainly relies on artificial methods to narrate and express emotions.
[0003] Due to the limitations of poetry writing methods, the speed and efficiency of traditional manual poetry writing are insufficient. Compared with automatic poetry writing by artificial intelligence, manual poetry writing usually requires more time and energy. Poets need to spend a lot of time thinking and creating processes in terms of conception, word selection, rhyme, etc., which will affect the speed and efficiency of poetry writing to a certain extent. Manual poetry writing is limited by the skills and styles they have mastered. Poets are usually limited by their own poetry writing skills and styles, and usually find it difficult to break through the existing creative mode. This greatly limits the innovation and diversity of poets, making poems appear monotonous or lacking in novelty. Manual poetry is limited by the poet's personal experience, emotional state, living environment and other factors, which may lead to limitations in the theme and emotional expression of poems. Different poets may have different understandings and feelings about the same thing, which greatly limits the diversity and depth of poetry. Summary of the invention
[0004] The purpose of this application is to provide a method for writing seven-character quatrain poems based on Python artificial intelligence to solve the problems raised in the above background technology.
[0005] To achieve the above-mentioned purpose, the present application provides the following technical solutions: a method for composing seven-character quatrain poems based on Python artificial intelligence, comprising an artificial intelligence poetry writing system, wherein the artificial intelligence poetry writing system comprises an intelligent automatic poetry writing module, a Baidu intelligent cloud module, and an Excel module, wherein the Excel module is a parent module of the intelligent poetry writing module, and the intelligent poetry writing module is a parent module of Baidu Intelligent Cloud. The Excel module is used to input text information, and the intelligent automatic poetry writing module is used to process the text information input by the Excel module, and the Baidu Intelligent Cloud module is used to generate corresponding verses from the processed text information.
[0006] A specific operation method of a method for making seven-character quatrain poems based on Python artificial intelligence includes the following steps:
[0007] S1: Import and verify keywords: Users manually input keywords in the poem on the intelligent automatic poem module page or import keywords into Excel in batches, read keywords row by row and column by column in Excel, and after the keyword import is completed, verify the keyword format, etc. After the text verification is correct, proceed to the next step. If there is a problem with the text verification, check whether the input format is in Excel format. If not, return to the previous step and re-enter;
[0008] S2: Keyword prompt: After the keyword is determined, the keyword format is checked. If the keyword check fails, the prompt word rewrite operation is performed. The prompt word rewrite is mainly to prompt and enrich the keywords, and add adjectives or other words to the keywords to express the keywords more clearly and carefully. For example, if the word "spring" is entered as the keyword, the prompt word rewrite prompts: As a poet, please write a seven-character quatrain with spring as the theme. How to write keywords, guide the keywords, and enrich the keyword content. The more detailed the keyword content entered, the more conducive it is to composing poetry;
[0009] S3: Baidu Smart Cloud module processing and keyword authentication: Keywords are directly input into the Baidu Smart Cloud module through verification or rewriting. The Baidu Wenxin Yiyan API interface in the Baidu Smart Cloud module performs text optimization operations on the keywords. The optimized keywords need to be authenticated. The authentication results are divided into successful authentication and failed authentication. If the authentication fails when calling the API interface, the verified keywords are reprocessed. After the authentication is successful, the Wenxin Yiyan API interface is called to feed back the results to the Baidu Smart Cloud interface.
[0010] S4: Intelligent automatic poetry writing module processing: After successful keyword authentication, the artificial intelligence calls the Baidu Smart Cloud poem interface, and carries the Baidu Wenxin Yiyan API interface to process the processed keywords as input parameters, and records the normal return of the poetry writing results by the interface. If there are sensitive words and other information, it returns failure. At this time, the artificial intelligence module processes the return results of the Baidu Smart Cloud interface and adjusts the relevant keywords to meet the requirements. After the poem is completed, the format of the successfully returned seven-character quatrain poem is processed. After the format processing is completed, the completed seven-character quatrain poem can be output. If the Baidu Smart Cloud interface fails to return data, it is necessary to create a data file to describe the reason for the failure and save the reason for the failure.
[0011] S5: System poetry writing process display: During the working process of the intelligent automatic poetry writing module, Baidu intelligent cloud module, and excel module, it is necessary to establish a system display interface, starting from the initial keyword import to the end of the generation of seven-character quatrains. During the whole process, it is necessary to determine whether the keywords of the generated poems are the keywords read by the imported excel module. If the keywords of the poems match the excel module, the system poetry writing process display will be retained and not displayed, indicating that there is no problem. If the keywords do not match, the entire process will be displayed, and the errors in the poetry writing process will be queried through the system poetry writing process display, and they will be modified.
[0012] Preferably, the computer programming data used in the intelligent automatic poetry writing module, Baidu intelligent cloud module, and excel module in the artificial intelligence poetry writing system mainly use python3.9 version.
[0013] Preferably, the system background image in the artificial intelligence poetry writing system uses python wxpython to draw the system page, loads the static image and converts it into a bitmap object, and displays it as the system background image through StaticBitmap.
[0014] Preferably, after the Baidu Smart Cloud outputs the poem, it uses the static text StaticText to display the interface call result, the call result includes the final poem or error message, and sets the background color and font of the static text control, the setting content includes the background color of the poem, and the setting result is no background color, so that the output result can be integrated into the background image without color difference.
[0015] Preferably, the artificial intelligence poetry writing system inputs keywords or imports Excel with preset keywords to extract poetry writing keywords. This process only supports Excel in xlsx format. The format check of keywords includes but is not limited to non-empty check, Chinese only check, incomprehensible word check, length check, etc.
[0016] Preferably, the working principle of the authentication interface is: calling the interface through request.post(url, headers) to obtain access_token, and the working principle of the calling interface of the intelligent cloud module is: calling the interface through request.post(url, headers, data = json.dumps(message body)) and returning the result.
[0017] Preferably, during the keyword authentication, the intelligent automatic poetry writing module obtains Access_token through the authentication interface of the Baidu Intelligent Cloud module. If the authentication fails, the subsequent operations are terminated and return to the initial operation.
[0018] Preferably, the subsequent specific operation after the keyword authentication is successful is that after the authentication is successful, the Baidu Smart Cloud module uses the Access_token and the processed keyword or the original keyword as input parameters, calls the Baidu Smart Cloud interface, and the interface returns the result in json format. And the json is formatted, the result is first split into substrings according to "\'" and "\\t", and the number of substrings after the split is determined to be 4, and a comma and a line break (",\n") are added to the end of each substring until a period and a line break (".\n") are added to the end of the last substring. If the number of substrings is not equal to 4, the error prompt of the returned result is rewritten in a targeted manner.
[0019] Preferably, the specific operation steps of the keyword authentication are: Step 1: Input keywords: depending on the results returned by the Baidu Wenxin Yiyan interface, use processed keywords or original keywords; Step 2: Input Access_token: Call the Baidu Cloud Authentication Interface to obtain the Access_token value; Step 3: Complete the poem writing call: Use the request interface to call the Baidu Smart Cloud poem interface; Step 4: Output the poem: Complete the format adjustment, and output the poem line breaks and other processing.
[0020] In summary, the technical effects and advantages of the present invention are as follows:
[0021] In the present invention, through the cooperation of the intelligent automatic poetry module, the Baidu intelligent cloud module and the excel module, the user inputs poetry keywords in the artificial intelligence automatic poetry system, and then verifies the keywords. The verification content includes but is not limited to non-empty and text input only. The verified keywords are enriched and authenticated through the Baidu Wenxin Yiyan authentication interface. After the authentication, the enriched keywords are used as Baidu Wenxin Yiyan interface API input parameters to optimize the keywords. Finally, the Baidu intelligent cloud poem interface is called, and the processed keywords are used as input parameters to output a seven-character quatrain. After the poem is output, the format is adjusted and output to the system page. Through this automatic creation method, the creation threshold is lowered, the creation cycle is shortened, the creation diversity is increased, and the creation speed is greatly improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0023] Figure 1 A schematic diagram of a human-working poetry system for a method of making seven-character quatrain poems based on Python artificial intelligence proposed in this application;
[0024] Figure 2 A schematic diagram of the operation steps of a method for making seven-character quatrain poems based on Python artificial intelligence proposed in this application;
[0025] Figure 3 A schematic diagram of the specific operation process of a method for making seven-character quatrain poems based on Python artificial intelligence proposed in this application;
[0026] Figure 4 This is a schematic diagram of the authentication operation flow of a method for writing seven-character quatrain poems based on Python artificial intelligence proposed in this application. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0028] Example: Reference Figure 1-4 The method shown is a method for writing seven-character quatrain poems based on Python artificial intelligence, including an artificial intelligence poetry writing system, the artificial intelligence poetry writing system includes an intelligent automatic poetry writing module, a Baidu intelligent cloud module, and an Excel module. The Excel module is a parent module of the intelligent poetry writing module, and the intelligent poetry writing module is a parent module of Baidu Intelligent Cloud. The Excel module is used to input text information, the intelligent automatic poetry writing module is used to process the text information input by the Excel module, and the Baidu Intelligent Cloud module is used to generate corresponding poems from the processed text information.
[0029] A specific operation method of a method for making seven-character quatrain poems based on Python artificial intelligence includes the following steps:
[0030] S1: Import and verify keywords: Users manually input keywords in the poem on the intelligent automatic poem module page or import keywords into Excel in batches, read keywords row by row and column by column in Excel, and after the keyword import is completed, verify the keyword format, etc. After the text verification is correct, proceed to the next step. If there is a problem with the text verification, check whether the input format is in Excel format. If not, return to the previous step and re-enter;
[0031] S2: Keyword prompt: After the keyword is determined, the keyword format is checked. If the keyword check fails, the prompt word rewrite operation is performed. The prompt word rewrite is mainly to prompt and enrich the keywords, and add adjectives or other words to the keywords to express the keywords more clearly and carefully. For example, if the word "spring" is entered as the keyword, the prompt word rewrite prompts: As a poet, please write a seven-character quatrain with spring as the theme. How to write keywords, guide the keywords, and enrich the keyword content. The more detailed the keyword content entered, the more conducive it is to composing poetry;
[0032] S3: Baidu Smart Cloud module processing and keyword authentication: Keywords are directly input into the Baidu Smart Cloud module through verification or rewriting. The Baidu Wenxin Yiyan API interface in the Baidu Smart Cloud module performs text optimization operations on the keywords. The optimized keywords need to be authenticated. The authentication results are divided into successful authentication and failed authentication. If the authentication fails when calling the API interface, the verified keywords are reprocessed. After the authentication is successful, the Wenxin Yiyan API interface is called to feed back the results to the Baidu Smart Cloud interface.
[0033] S4: Intelligent automatic poetry writing module processing: After successful keyword authentication, the artificial intelligence calls the Baidu Smart Cloud poem interface, and carries the Baidu Wenxin Yiyan API interface to process the processed keywords as input parameters, and records the normal return of the poetry writing results by the interface. If there are sensitive words and other information, it returns failure. At this time, the artificial intelligence module processes the return results of the Baidu Smart Cloud interface and adjusts the relevant keywords to meet the requirements. After the poem is completed, the format of the successfully returned seven-character quatrain poem is processed. After the format processing is completed, the completed seven-character quatrain poem can be output. If the Baidu Smart Cloud interface fails to return data, it is necessary to create a data file to describe the reason for the failure and save the reason for the failure.
[0034] S5: System poetry writing process display: During the working process of the intelligent automatic poetry writing module, Baidu intelligent cloud module, and excel module, it is necessary to establish a system display interface, starting from the initial keyword import to the end of the generation of seven-character quatrains. During the whole process, it is necessary to determine whether the keywords of the generated poems are the keywords read by the imported excel module. If the keywords of the poems match the excel module, the system poetry writing process display will be retained and not displayed, indicating that there is no problem. If the keywords do not match, the entire process will be displayed, and the errors in the poetry writing process will be queried through the system poetry writing process display, and they will be modified.
[0035] As a preferred implementation of this embodiment, the computer programming data used in the intelligent automatic poetry writing module, Baidu intelligent cloud module, and excel module in the artificial intelligence poetry writing system mainly use the python3.9 version.
[0036] As a preferred implementation of this embodiment, the system background image in the artificial intelligence poetry writing system uses python wxpython to draw the system page, loads the static image and converts it into a bitmap object, and displays it as the system background image through StaticBitmap.
[0037] As a preferred implementation of this embodiment, after Baidu Smart Cloud outputs the poem, it uses the static text StaticText to display the interface call result. The call result includes the final poem or error message, and the background color and font are set for the static text control. The setting content includes the background color of the poem. The setting result is no background color, which makes it easier for the output result to be integrated into the background image without color difference.
[0038] As a preferred implementation of this embodiment, the artificial intelligence poetry writing system inputs keywords or imports Excel with preset keywords to extract poetry writing keywords. This process only supports Excel in xlsx format. The format check of keywords includes but is not limited to non-empty check, Chinese only check, incomprehensible word check, length check, etc.
[0039] As a preferred implementation mode of this embodiment, the working principle of the authentication interface during keyword authentication is to call the interface through request.post(url,headers) to obtain access_token. The working principle of the calling interface of the smart cloud module calling Baidu Wenxin Yiyan is: calling the interface through request.post(url,headers,data=json.dumps(message body)) and returning the result.
[0040] As a preferred implementation of this embodiment, during keyword authentication, the intelligent automatic poetry writing module obtains Access_token through the authentication interface of the Baidu Intelligent Cloud Module. If the authentication fails, the subsequent operations are terminated and return to the initial operation.
[0041] As a preferred implementation of this embodiment, the subsequent specific operation after the keyword authentication is successful is that after the authentication is successful, the Baidu Smart Cloud module uses the Access_token and the processed keywords or the original keywords as input parameters, calls the Baidu Smart Cloud interface, and the interface returns the result in json format. And the json is formatted, the result is first split into substrings according to "\'" and "\\t", and the number of substrings after the split is determined to be 4, and a comma and a line break (",\n") are added to the end of each substring until a period and a line break (".\n") are added to the end of the last substring. If the number of substrings is not equal to 4, the error prompt of the returned result is rewritten in a targeted manner.
[0042] As a preferred implementation method of this embodiment, the specific operation steps of keyword authentication are: Step 1: Enter keywords: depending on the results returned by the Baidu Wenxin Yiyan interface, use processed keywords or original keywords; Step 2: Enter Access_token: call the Baidu Cloud Authentication Interface to obtain the Access_token value; Step 3: Complete the poem writing call: use the request interface to call the Baidu Smart Cloud poem interface; Step 4: Output the poem: complete the format adjustment, and output the poem line breaks and other processing.
[0043] Working principle of the present invention:
[0044] In the present invention, through the cooperation of the intelligent automatic poetry module, the Baidu intelligent cloud module and the excel module, the user inputs poetry keywords in the artificial intelligence automatic poetry system, and then verifies the keywords. The verification content includes but is not limited to non-empty and text input only. The verified keywords are enriched and authenticated through the Baidu Wenxin Yiyan authentication interface. After the authentication, the enriched keywords are used as Baidu Wenxin Yiyan interface API input parameters to optimize the keywords. Finally, the Baidu intelligent cloud poem interface is called, and the processed keywords are used as input parameters to output a seven-character quatrain. After the poem is output, the format is adjusted and output to the system page. Through this automatic creation method, the creation threshold is lowered, the creation cycle is shortened, the creation diversity is increased, and the creation speed is greatly improved.
[0045] Finally, it should be noted that the above are only preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, it is still possible for those skilled in the art to modify the technical solutions described in the aforementioned embodiments, or to make equivalent substitutions for some of the technical features therein. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for writing seven-character quatrain poems based on Python artificial intelligence, including an artificial intelligence poetry writing system, characterized in that: The artificial intelligence poetry writing system includes an intelligent automatic poetry writing module, a Baidu intelligent cloud module, and an excel module. The excel module is the upper module of the intelligent poetry writing module, and the intelligent poetry writing module is the upper module of Baidu intelligent cloud. The excel module is used to input text information, and the intelligent automatic poetry writing module is used to process the text information input by the excel module, and the Baidu intelligent cloud module is used to generate corresponding verses from the processed text information.
2. The specific operation method of the method for making seven-character quatrain poems based on Python artificial intelligence according to claim 1 is characterized in that: The following steps are involved: S1: Import and verify keywords: Users manually input keywords in the poem on the intelligent automatic poem module page or import keywords into Excel in batches, read keywords row by row and column by column in Excel, and after the keyword import is completed, verify the keyword format, etc. After the text verification is correct, proceed to the next step. If there is a problem with the text verification, check whether the input format is in Excel format. If not, return to the previous step and re-enter; S2: Keyword prompt: After the keyword is determined, the keyword format is checked. If the keyword check fails, the prompt word rewrite operation is performed. The prompt word rewrite is mainly to prompt and enrich the keyword, add adjectives or other words to the keyword to express the keyword more clearly and carefully. For example, if the word "spring" is entered as the keyword, the prompt word rewrite prompts: As a poet, please write a seven-character quatrain with spring as the theme. How to write the keywords, guide the keywords, and enrich the keyword content. The more detailed the keyword content entered, the more conducive it is to composing poetry; S3: Baidu Smart Cloud module processing and keyword authentication: Keywords are directly input into the Baidu Smart Cloud module through verification or rewriting. The Baidu Wenxin Yiyan API interface in the Baidu Smart Cloud module performs text optimization operations on the keywords. The optimized keywords need to be authenticated. The authentication results are divided into successful authentication and failed authentication. If the authentication fails when calling the API interface, the verified keywords are reprocessed. After the authentication is successful, the Wenxin Yiyan API interface is called to feed back the results to the Baidu Smart Cloud interface. S4: Intelligent automatic poetry writing module processing: After successful keyword authentication, the artificial intelligence calls the Baidu Smart Cloud poem interface, and carries the Baidu Wenxin Yiyan API interface to process the processed keywords as input parameters, and records the normal return of the poetry writing results by the interface. If there are sensitive words and other information, it returns failure. At this time, the artificial intelligence module processes the return results of the Baidu Smart Cloud interface and adjusts the relevant keywords to meet the requirements. After the poem is completed, the format of the successfully returned seven-character quatrain poem is processed. After the format processing is completed, the completed seven-character quatrain poem can be output. If the Baidu Smart Cloud interface fails to return data, it is necessary to create a data file to describe the reason for the failure and save the reason for the failure. S5: System poetry writing process display: During the working process of the intelligent automatic poetry writing module, Baidu intelligent cloud module, and excel module, it is necessary to establish a system display interface, starting from the initial keyword import to the end of the generation of seven-character quatrains. During the whole process, it is necessary to determine whether the keywords of the generated poems are the keywords read by the imported excel module. If the keywords of the poems match the excel module, the system poetry writing process display will be retained and not displayed, indicating that there is no problem. If the keywords do not match, the entire process will be displayed, and the errors in the poetry writing process will be queried through the system poetry writing process display, and they will be modified.
3. The method for making seven-character quatrain poems based on Python artificial intelligence according to claim 1, characterized in that: The computer programming data used in the intelligent automatic poetry writing module, Baidu intelligent cloud module, and excel module in the artificial intelligence poetry writing system mainly use python3.9 version.
4. The method for making seven-character quatrain poems based on Python artificial intelligence according to claim 3, characterized in that: The system background image in the artificial intelligence poetry writing system uses python wxpython to draw the system page, loads the static image and converts it into a bitmap object, and displays it as the system background image through StaticBitmap.
5. The method for making seven-character quatrain poems based on Python artificial intelligence according to claim 3, characterized in that: After Baidu Smart Cloud outputs the poem, it uses the static text StaticText to display the interface call result. The call result includes the final poem or error message, and the background color and font are set for the static text control. The setting content includes the background color of the poem. The setting result is no background color, which makes it easier for the output result to be integrated into the background image without color difference.
6. The method for making seven-character quatrain poems based on Python artificial intelligence according to claim 3, characterized in that: The artificial intelligence poetry writing system inputs keywords or imports Excel with preset keywords to extract poetry writing keywords. This process only supports Excel in xlsx format. The format check of keywords includes but is not limited to non-empty check, Chinese only check, incomprehensible word check, length check, etc.
7. The method for making seven-character quatrain poems based on Python artificial intelligence according to claim 2, characterized in that: The working principle of the authentication interface is: calling the interface through request.post(url, headers) to obtain access_token, and the working principle of the calling interface of the intelligent cloud module is: calling the interface through request.post(url, headers, data = json.dumps(message body)) and returning the result.
8. The method for making seven-character quatrain poems based on Python artificial intelligence according to claim 2, characterized in that: During the keyword authentication, the intelligent automatic poetry writing module obtains Access_token through the authentication interface of the Baidu Intelligent Cloud module. If the authentication fails, the subsequent operations end and return to the initial operation.
9. The method for making seven-character quatrain poems based on Python artificial intelligence according to claim 2, characterized in that: The subsequent specific operations after the keyword authentication is successful are as follows: After the authentication is successful, the Baidu Smart Cloud module uses the Access_token and the processed keyword or the original keyword as input parameters, calls the Baidu Smart Cloud interface, and the interface returns the result in json format. And the json is formatted, first the result is split into substrings according to "\'" and "\\t", and the number of substrings after the split is determined to be 4, and a comma and a line break (",\n") are added to the end of each substring until a period and a line break (".\n") are added to the end of the last substring. If the number of substrings is not equal to 4, the error prompt of the returned result is rewritten in a targeted manner.
10. The method for making seven-character quatrain poems based on Python artificial intelligence according to claim 9, characterized in that: The specific operation steps of the keyword authentication are: Step 1: Enter keywords: depending on the results returned by the Baidu Wenxin Yiyan interface, use processed keywords or original keywords; Step 2: Enter Access_token: call the Baidu Cloud Authentication Interface to obtain the Access_token value; Step 3: Complete the poem writing call: use the request interface to call the Baidu Smart Cloud poem interface; Step 4: Output the poem: complete the format adjustment, and output the poem line breaks and other processing.
