Spaces:
Sleeping
Sleeping
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): | |
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('awda') | |
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) | |