Spaces:
Sleeping
Sleeping
update
Browse files- app.py +12 -23
- requirements.txt +3 -4
app.py
CHANGED
@@ -1,27 +1,16 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
from dotenv import load_dotenv
|
4 |
|
5 |
-
# Load
|
6 |
-
|
7 |
-
|
8 |
-
# Set the OpenAI API key from environment variable
|
9 |
-
openai.api_key = os.getenv("OPENAI_API_KEY")
|
10 |
|
11 |
def generate_text(prompt):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
max_tokens=150,
|
19 |
-
n=1,
|
20 |
-
stop=None,
|
21 |
-
temperature=0.7,
|
22 |
-
)
|
23 |
-
return response.choices[0].message['content'].strip()
|
24 |
|
25 |
-
#
|
26 |
-
|
27 |
-
print(generate_text(prompt))
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
3 |
|
4 |
+
# Load the GPT-Neo model and tokenizer
|
5 |
+
generator = pipeline("text-generation", model="EleutherAI/gpt-neo-125M")
|
|
|
|
|
|
|
6 |
|
7 |
def generate_text(prompt):
|
8 |
+
# Generate text using GPT-Neo
|
9 |
+
result = generator(prompt, max_length=100, num_return_sequences=1)
|
10 |
+
return result[0]["generated_text"]
|
11 |
+
|
12 |
+
# Create a Gradio interface
|
13 |
+
iface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="GPT-Neo Text Generator")
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# Launch the interface
|
16 |
+
iface.launch(share=True)
|
|
requirements.txt
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
gradio
|
4 |
-
torch # Include this if you are working with PyTorch models
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
gradio
|
|