Papajams commited on
Commit
d7d079f
·
1 Parent(s): 73ca7db

Upload orthogonizerapp.py

Browse files
Files changed (1) hide show
  1. orthogonizerapp.py +43 -0
orthogonizerapp.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+
4
+ # Function to process input and generate output
5
+ def orthogonizer(text, api_key):
6
+ prompt = f"Given the input '{text}', please provide an orthogonal perspective."
7
+
8
+ # Set up OpenAI API
9
+ openai.api_key = api_key
10
+
11
+ # Call OpenAI API to process the input text
12
+ response = openai.Completion.create(
13
+ engine="text-davinci-003",
14
+ prompt=prompt,
15
+ max_tokens=200, #longer responses
16
+ n=1, # one response
17
+ temperature=0.5, # more deterministic output
18
+ )
19
+
20
+ # Extract the generated orthogonal perspective from the OpenAI response
21
+ orthogonal_perspective = response.choices[0]['text'].strip()
22
+
23
+ # Remove the brackets and the words "orthogonal perspective"
24
+ orthogonal_perspective = orthogonal_perspective.replace("{", "").replace("}", "").replace("Orthogonal Perspective: ", "")
25
+
26
+ return orthogonal_perspective
27
+
28
+ # Set up Gradio interface
29
+ input_text = gr.inputs.Textbox(label="Enter your input text")
30
+ api_key_text = gr.inputs.Textbox(label="Enter your OpenAI API key")
31
+ output_text = gr.outputs.Textbox(label="Output")
32
+
33
+ interface = gr.Interface(
34
+ fn=orthogonizer,
35
+ inputs=[input_text, api_key_text],
36
+ outputs=output_text,
37
+ title="Orthogonizer App",
38
+ description="Enter your text and get an orthogonal perspective.",
39
+ article="",
40
+ )
41
+
42
+ if __name__ == "__main__":
43
+ interface.launch(share=True)