Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,29 @@
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
| 3 |
-
import random
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
openai.api_key = api_key
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
"Don’t look now, but they’re right behind you.",
|
| 12 |
-
"I need to talk to you about something.",
|
| 13 |
-
"Oh no! You’re hurt!",
|
| 14 |
-
"And that's why you're fired.",
|
| 15 |
-
"What’s that on your arm?",
|
| 16 |
-
"Is this seat taken?",
|
| 17 |
-
"I can’t believe you actually got me a pony!"
|
| 18 |
-
]
|
| 19 |
-
|
| 20 |
-
# Randomly select one of the provided prompts
|
| 21 |
-
selected_prompt = random.choice(sample_prompts)
|
| 22 |
-
|
| 23 |
-
# Build the prompt to guide the model towards generating a one-line dialogue
|
| 24 |
-
prompt_text = (
|
| 25 |
-
f"Based on the scenario: '{selected_prompt}', generate a one-line dialogue:\n"
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
# Generate dialogue based on the selected prompt
|
| 29 |
response = openai.Completion.create(
|
| 30 |
engine="davinci",
|
| 31 |
-
prompt=
|
| 32 |
-
max_tokens=
|
| 33 |
)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
inputs=[
|
| 44 |
-
gr.Textbox(label="OpenAI API Key"),
|
| 45 |
-
gr.Button(label="Generate")
|
| 46 |
-
],
|
| 47 |
-
outputs="text",
|
| 48 |
-
live=False # Set to False so the function only runs when the button is pressed
|
| 49 |
)
|
| 50 |
-
|
| 51 |
-
# Launch the
|
| 52 |
-
|
| 53 |
|
| 54 |
if __name__ == "__main__":
|
| 55 |
-
|
|
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
+
# Set up the OpenAI API key
|
| 5 |
+
openai.api_key = 'YOUR_OPENAI_API_KEY'
|
|
|
|
| 6 |
|
| 7 |
+
def generate_statement():
|
| 8 |
+
# Generate a statement using OpenAI's GPT 3.5 model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
response = openai.Completion.create(
|
| 10 |
engine="davinci",
|
| 11 |
+
prompt="Write a short one-line statement similar to common dialogue from movies or books:",
|
| 12 |
+
max_tokens=50
|
| 13 |
)
|
| 14 |
+
return response.choices[0].text.strip()
|
| 15 |
+
|
| 16 |
+
def main():
|
| 17 |
+
# Define the UI components using gr.Interface
|
| 18 |
+
interface = gr.Interface(
|
| 19 |
+
fn=generate_statement, # Function to call on button press
|
| 20 |
+
inputs=[], # No input components
|
| 21 |
+
outputs="text", # Output is a text area
|
| 22 |
+
live=True # Generate statement without requiring a button press
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
)
|
| 24 |
+
|
| 25 |
+
# Launch the UI on Spaces
|
| 26 |
+
interface.launch(share=True)
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
| 29 |
+
main()
|