A platform using ChatGPT to verify that ads comply with legal regulations and regulations for advertising on social media platforms in the Kingdom of Saudi Arabia and knowing their fines in case of violation.
- This code defines a chatbot that checks whether an advertisement is valid according to certain rules. It uses the GPT-3 language model to generate responses. The chatbot takes input text as a parameter and returns a JSON object indicating whether the advertisement is valid, which rules it violates (if any), and the corresponding financial penalty ranges.
-
The
construct_index
function constructs an index for the GPT-3 model using a directory of documents. It sets various parameters such asmax_input_size
,num_outputs
,max_chunk_overlap
, andchunk_size_limit
. It then creates aPromptHelper
object, anLLMPredictor
object, and aSimpleDirectoryReader
object to load the data. It creates aGPTSimpleVectorIndex
object using the loaded data and the previously defined objects. It saves the index to disk and returns it. -
The
chatbot
function takes an input text as a parameter, loads the index from disk, and sets the prompt using the input text and therule_map
dictionary. It queries the index using the prompt and stores the response in a JSON object. If the input text does not contain the words "ad" or "advertisement", the chatbot adds "Rule1.24" to the list of violated rule numbers. It returns the response.
Finally, the code creates a Gradio interface for the chatbot, sets the input to a text box, and sets the output to text. It constructs the index using the construct_index
function and launches the interface.