soroushheidary commited on
Commit
c0b1c1a
1 Parent(s): 909c2b4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+
4
+ # Set your OpenAI API key here
5
+ api_key = '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'
6
+ organization='org-bFx0b9nX8ik0FHAoj7pZufNP'
7
+ openai.api_key = api_key
8
+ openai.organization = organization #os.getenv("ORG")
9
+ 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'"
10
+ model_name = 'ft:gpt-3.5-turbo-1106:infercia::8n84ogUY'
11
+
12
+ def check_grammar(text):
13
+ try:
14
+ response = openai.ChatCompletion.create(
15
+ model=model_name,
16
+ messages=[{
17
+ "role": "system",
18
+ "content": system_message,
19
+ },
20
+ {
21
+ "role": "user",
22
+ "content": text,
23
+ }],
24
+ )
25
+ print(response.choices[0])
26
+ return response.choices[0].message.content
27
+ except Exception as e:
28
+ print('awda')
29
+ print(response.choices[0])
30
+ return str(e)
31
+
32
+ # Gradio interface
33
+ iface = gr.Interface(
34
+ fn=check_grammar,
35
+ inputs="text",
36
+ outputs="text",
37
+ title="Grammar Checker",
38
+ description="Enter text to check for grammar errors using OpenAI."
39
+ )
40
+
41
+ if __name__ == "__main__":
42
+ iface.launch(share=True)