Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai as ai
|
2 |
+
|
3 |
+
ai.api_key = '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' # replace with your key from earlier
|
4 |
+
|
5 |
+
import os
|
6 |
+
import openai as ai
|
7 |
+
|
8 |
+
# Get the key from an environment variable on the machine it is running on
|
9 |
+
# ai.api_key = os.environ.get("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")
|
10 |
+
|
11 |
+
def generate_gpt3_response(user_text, print_output=False):
|
12 |
+
"""
|
13 |
+
Query OpenAI GPT-3 for the specific key and get back a response
|
14 |
+
:type user_text: str the user's text to query for
|
15 |
+
:type print_output: boolean whether or not to print the raw output JSON
|
16 |
+
"""
|
17 |
+
completions = ai.Completion.create(
|
18 |
+
engine='text-davinci-003', # Determines the quality, speed, and cost.
|
19 |
+
temperature=0.5, # Level of creativity in the response
|
20 |
+
prompt=user_text, # What the user typed in
|
21 |
+
max_tokens=100, # Maximum tokens in the prompt AND response
|
22 |
+
n=1, # The number of completions to generate
|
23 |
+
stop=None, # An optional setting to control response generation
|
24 |
+
)
|
25 |
+
|
26 |
+
# Displaying the output can be helpful if things go wrong
|
27 |
+
if print_output:
|
28 |
+
print(completions)
|
29 |
+
|
30 |
+
# Return the first choice's text
|
31 |
+
return completions.choices[0].text
|
32 |
+
|
33 |
+
models = ai.Model.list()
|
34 |
+
|
35 |
+
for model in models.data:
|
36 |
+
(model.id)
|
37 |
+
|
38 |
+
if __name__ == '__main__':
|
39 |
+
prompt = 'Magento with 0% plagiarism'
|
40 |
+
response = generate_gpt3_response(prompt)
|
41 |
+
|
42 |
+
print(response)
|
43 |
+
|
44 |
+
import gradio as gr
|
45 |
+
|
46 |
+
input_text = gr.inputs.Textbox(lines=20, label='Input Text')
|
47 |
+
output_text = gr.outputs.Textbox(label='Output Text')
|
48 |
+
|
49 |
+
app = gr.Interface(paraphrase, inputs=input_text,css="""span.svelte-1l2rj76{color: #591fc9;font-size: 18px;
|
50 |
+
font-weight: 600;}.secondary.svelte-1ma3u5b{background: #591fc9; color: #fff;}.secondary.svelte-1ma3u5b:hover{background:#8a59e8;color:#000;}
|
51 |
+
.svelte-2xzfnp textarea {border: 1px solid #591fc9}.primary.svelte-1ma3u5b{background: #f8d605;color: #000;}.primary.svelte-1ma3u5b:hover{background: #ffe751;color: #591fc9;} """, outputs=output_text, title='GPT-2 Article Rewriter', description='Generate a paraphrased output while preserving the meaning of the input text using OpenAI GPT-2 model.')
|
52 |
+
|
53 |
+
# Launch the user interface
|
54 |
+
app.launch(inline=False)
|