Daniton commited on
Commit
fc66424
·
1 Parent(s): d4dc9b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -22
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  import openai
3
- import time
4
 
5
  # Authenticate with OpenAI API
6
  openai.api_key = "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"
@@ -19,33 +18,14 @@ def generate_text(prompt):
19
  stop=None,
20
  temperature=0.5,
21
  )
22
- generated_text = response.choices[0].text.strip()
23
- return generated_text
24
-
25
- def generate_text_slowly(prompt):
26
- # Generate text character by character, with a delay between each character
27
- generated_text = ""
28
- response = openai.Completion.create(
29
- engine=model_engine,
30
- prompt=prompt,
31
- max_tokens=1024,
32
- n=1,
33
- stop=None,
34
- temperature=0.5,
35
- )
36
- generated_chars = response.choices[0].text.strip()
37
- for char in generated_chars:
38
- generated_text += char
39
- time.sleep(0.05) # Add a small delay between characters to simulate typing
40
- return generated_text
41
 
42
  # Create Gradio interface
43
  interface = gr.Interface(
44
- generate_text_slowly,
45
  inputs=gr.inputs.Textbox(prompt),
46
  outputs=gr.outputs.Textbox(),
47
  title="GPT-2 Text Generation",
48
- description="Enter a short prompt and watch as GPT-2 generates text based on your input.",
49
  )
50
 
51
  # Launch the interface
 
1
  import gradio as gr
2
  import openai
 
3
 
4
  # Authenticate with OpenAI API
5
  openai.api_key = "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"
 
18
  stop=None,
19
  temperature=0.5,
20
  )
21
+ return response.choices[0].text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  # Create Gradio interface
24
  interface = gr.Interface(
25
+ generate_text,
26
  inputs=gr.inputs.Textbox(prompt),
27
  outputs=gr.outputs.Textbox(),
28
  title="GPT-2 Text Generation",
 
29
  )
30
 
31
  # Launch the interface