Spaces:
Sleeping
Sleeping
Create main.py
Browse files
main.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
|
4 |
+
# Initialize the OpenAI API with your API key
|
5 |
+
openai.api_key = "openai-api-key"
|
6 |
+
|
7 |
+
def generate_text(prompt, max_length=100, temperature=1.0):
|
8 |
+
# Generate text using GPT-3
|
9 |
+
response = openai.Completion.create(
|
10 |
+
engine="text-davinci-003", # You can also use other engines like "gpt-3.5-turbo"
|
11 |
+
prompt=prompt,
|
12 |
+
max_tokens=max_length,
|
13 |
+
temperature=temperature,
|
14 |
+
n=1,
|
15 |
+
stop=None
|
16 |
+
)
|
17 |
+
return response.choices[0].text.strip()
|
18 |
+
|
19 |
+
# Create a Gradio interface
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=generate_text,
|
22 |
+
inputs=[
|
23 |
+
gr.Textbox(lines=3, placeholder="Enter your prompt here...", label="Prompt"),
|
24 |
+
gr.Slider(minimum=50, maximum=500, value=100, label="Max Length"),
|
25 |
+
gr.Slider(minimum=0.1, maximum=1.5, value=1.0, label="Temperature"),
|
26 |
+
],
|
27 |
+
outputs=gr.Textbox(label="Generated Text"),
|
28 |
+
title="GPT-3 Text Generator",
|
29 |
+
description="Enter a prompt and generate text using the GPT-3 model."
|
30 |
+
)
|
31 |
+
|
32 |
+
# Launch the interface
|
33 |
+
iface.launch(share=True)
|