Spaces:
Sleeping
Sleeping
Update
Browse files
.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
OPENAI_API_KEY = org-TgJiwZlNrnXba0FGCx33ZaAs
|
app.py
CHANGED
@@ -1,20 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
model = GPT2LMHeadModel.from_pretrained(model_name)
|
7 |
-
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Create a Gradio interface
|
17 |
-
iface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="GPT-
|
18 |
|
19 |
# Launch the interface
|
20 |
-
iface.launch(
|
|
|
1 |
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
|
5 |
+
# Set your OpenAI API key
|
6 |
+
openai.api_key = os.getenv("OPENAI_API_KEY") # Make sure to set this environment variable in Hugging Face Spaces
|
|
|
|
|
7 |
|
8 |
+
def generate_text(prompt):
|
9 |
+
response = openai.Completion.create(
|
10 |
+
engine="text-davinci-003", # You can use other engines like "text-curie-001" or "text-babbage-001"
|
11 |
+
prompt=prompt,
|
12 |
+
max_tokens=150,
|
13 |
+
n=1,
|
14 |
+
stop=None,
|
15 |
+
temperature=0.7,
|
16 |
+
)
|
17 |
+
return response.choices[0].text.strip()
|
18 |
|
19 |
# Create a Gradio interface
|
20 |
+
iface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="GPT-3 Text Generator", description="Enter a prompt to generate text using GPT-3.")
|
21 |
|
22 |
# Launch the interface
|
23 |
+
iface.launch(public=True)
|