Serg4451D commited on
Commit
5469a85
·
1 Parent(s): 22a06dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -25
app.py CHANGED
@@ -1,36 +1,25 @@
1
  import openai
2
  import streamlit as st
3
 
4
- # Set OpenAI API key
5
  openai.api_key = "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"
6
 
7
- # Define function to generate text using OpenAI API
8
- def edit_text(prompt):
9
- response = openai.Edit.create(
10
- model="code-davinci-edit-001",
11
- instruction="",
12
- prompt=prompt,
13
- max_tokens=950,
14
- stop=None,
15
- )
16
- return response.choices[0].text
17
-
18
- # Set up Streamlit app
19
  def main():
20
- st.title("OpenAI Text Editor")
 
21
 
22
- # Get user input
23
- prompt = st.text_area("Enter your text here", height=200)
 
 
 
 
 
 
24
 
25
- # Generate text using OpenAI API
26
- if st.button("Edit Text"):
27
- if prompt:
28
- with st.spinner("Editing text..."):
29
- edited_text = edit_text(prompt)
30
- st.write("Edited text:")
31
- st.write(edited_text)
32
- else:
33
- st.warning("Please enter some text.")
34
 
35
  if __name__ == "__main__":
36
  main()
 
 
1
  import openai
2
  import streamlit as st
3
 
4
+ # Подключение к API OpenAI
5
  openai.api_key = "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"
6
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def main():
8
+ st.title("OpenAI Code Editor")
9
+ request = st.text_input("Enter your request:")
10
 
11
+ if request:
12
+ response = openai.Edit.create(
13
+ model="code-davinci-edit-001",
14
+ prompt=request,
15
+ temperature=0.7,
16
+ max_tokens=1000,
17
+ instruction="Please edit the code below to make it work as intended."
18
+ )
19
 
20
+ code = response["choices"][0]["text"]
21
+ st.code(code, language="python")
 
 
 
 
 
 
 
22
 
23
  if __name__ == "__main__":
24
  main()
25
+