File size: 1,503 Bytes
c0b1c1a
 
 
 
 
 
 
 
 
 
 
 
9ea48b0
c0b1c1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b6ac7d5
c0b1c1a
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
import gradio as gr
import openai

# Set your OpenAI API key here
api_key = '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'
organization='org-bFx0b9nX8ik0FHAoj7pZufNP'
openai.api_key = api_key
openai.organization = organization #os.getenv("ORG")
system_message = "A model that takes sentence in English which may contain grammatical errors, and responds with 1-the corrected version of the English sentence in the first line and then, 2-for each error -> correction, a concise explanation in Persian language. if there are no errors you respond with 'No Errors'"
model_name = 'ft:gpt-3.5-turbo-1106:infercia::8n84ogUY'

def check_grammar(text):
    response = 'Error Communicating'
    try:
        response = openai.ChatCompletion.create(
                model=model_name,
                messages=[{
                    "role": "system",
                    "content": system_message,
                },
                {
                    "role": "user",
                    "content": text,
                }],
        )
        print(response.choices[0])
        return response.choices[0].message.content
    except Exception as e:
        print('Error Happened Here!')
        print(response.choices[0])
        return str(e)

# Gradio interface
iface = gr.Interface(
    fn=check_grammar,
    inputs="text",
    outputs="text",
    title="Grammar Checker",
    description="Enter text to check for grammar errors using OpenAI."
)

if __name__ == "__main__":
    iface.launch(share=True)