File size: 1,598 Bytes
83330e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd1f75b
1
2
3
4
5
6
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
import openai
import gradio as gr
import re

# Set up the OpenAI API key
openai.api_key = "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 "

def classify_words(text):
    # Use the OpenAI GPT-3 model to identify hard English words in the input text
    response = openai.Completion.create(
        engine="text-davinci-003",
        prompt=f"Identify hard English words in the following text and provide their simple English meanings:\n\n{text}\n\nHard words:",
        max_tokens=1000,
        n=1,
        stop=None,
        temperature=0.5,
    )

    # Parse the OpenAI API response to extract the identified hard English words and their simple English meanings
    output = response.choices[0].text.strip()
    hard_words_list = re.findall(r"([\w'-]+):\s(.+)", output)
    hard_words_dict = dict(hard_words_list)

    # Generate the output text with the identified hard English words and their simple English meanings
    output_text = "Identified hard English words and their simple English meanings:\n\n"
    for word, meaning in hard_words_dict.items():
        output_text += f"{word}: {meaning}\n"
    
    return output_text

# Set up the Gradio interface
input_text = gr.inputs.Textbox(label="Enter a paragraph of text with hard English words")
output_text = gr.outputs.Textbox(label="Simple English meanings of identified hard English words")

gr.Interface(classify_words, inputs=input_text, outputs=output_text, title="Hard English Word Classifier", description="Enter a paragraph of text with hard English words to identify and provide their simple English meanings.").launch()