Spaces:
Runtime error
Runtime error
Download app.py from dc07/studytools: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/dc07/studytools/resolve/main/app.py
- Command line
-
hf download hf://spaces/dc07/studytools/app.py
-
curl -L -o app.py https://huggingface.co/spaces/dc07/studytools/resolve/main/app.py
1.6 kB
| 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() | |