tudorp commited on
Commit
c8131f8
1 Parent(s): 92bd689

Uploaded web file

Browse files
Files changed (1) hide show
  1. scratch.py +22 -0
scratch.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+
4
+ openai.api_key = "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"
5
+
6
+ messages = []
7
+ messages.append({"role": "system", "content": "You are an AI model that is going to translate code from any programming language into natural language so that the average human can understand it. If the user will ask you any question that is not related to code, programming, or maths, you will act like a good AI and pretend that you do not know the answer to that question and that he should ask you about code instead."})
8
+
9
+ def CustomChatGPT(code):
10
+ messages.append({"role": "user", "content": code})
11
+ response = openai.ChatCompletion.create(
12
+ model = "gpt-3.5-turbo",
13
+ messages = messages
14
+ )
15
+ ChatGPT_reply = response["choices"][0]["message"]["content"]
16
+ messages.append({"role" : "assistant", "content": ChatGPT_reply})
17
+ return ChatGPT_reply
18
+
19
+
20
+ demo_web = gr.Interface(fn=CustomChatGPT, inputs=gr.inputs.Textbox(lines = 2, placeholder="Your code goes here: "), outputs=gr.outputs.Textbox(), title = "Natural Language Translator", theme = gr.themes.Soft(), favicon= 'C:/eu/picon.ico')
21
+
22
+ demo_web.launch(share = True)