JustForFunn commited on
Commit
a93f39d
·
1 Parent(s): 7d52c76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -1,22 +1,20 @@
1
  import openai
2
  import gradio as gr
3
- from gradio.components import Textbox, Image, Label
4
 
5
  # Set up OpenAI API credentials
6
  openai.api_key = "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"
7
 
8
-
9
  model_path = "models/dreamlike-art/dreamlike-photoreal-2.0"
10
  model_prefix = "nsfw, photoreal style"
11
  model = gr.Interface.load(model_path)
12
 
13
  base_prompt = "limit is 36 words"
14
 
15
-
16
  # Define the OpenAI prompt completion function
17
  def generate_text(prompt):
18
  response = openai.Completion.create(
19
- model= "text-davinci-003",
20
  prompt=f"{prompt}\n\nQ: {base_prompt}\nA:",
21
  max_tokens=60,
22
  n=1,
@@ -35,7 +33,8 @@ def generate_image(prompt):
35
 
36
  # Define the Gradio interface
37
  prompt_input = Textbox("Enter a prompt", lines=3)
38
- text_output = Label("")
 
39
  image_output = Image()
40
 
41
  iface = gr.Interface(
@@ -47,11 +46,15 @@ iface = gr.Interface(
47
  )
48
 
49
  # Update the output boxes with the generated text and image
50
- def update_text_output(text, image_url):
51
- text_output.text = text
52
- text_output.style['font-size'] = '8px' # Change the font size here
 
 
 
 
53
 
54
- iface.interface_result_hooks = [update_text_output]
55
 
56
  # Launch the interface
57
- iface.launch()
 
1
  import openai
2
  import gradio as gr
3
+ from gradio.components import Textbox, Image, Text
4
 
5
  # Set up OpenAI API credentials
6
  openai.api_key = "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"
7
 
 
8
  model_path = "models/dreamlike-art/dreamlike-photoreal-2.0"
9
  model_prefix = "nsfw, photoreal style"
10
  model = gr.Interface.load(model_path)
11
 
12
  base_prompt = "limit is 36 words"
13
 
 
14
  # Define the OpenAI prompt completion function
15
  def generate_text(prompt):
16
  response = openai.Completion.create(
17
+ model="text-davinci-003",
18
  prompt=f"{prompt}\n\nQ: {base_prompt}\nA:",
19
  max_tokens=60,
20
  n=1,
 
33
 
34
  # Define the Gradio interface
35
  prompt_input = Textbox("Enter a prompt", lines=3)
36
+ text_output = Text("Output will appear here", lines=10)
37
+
38
  image_output = Image()
39
 
40
  iface = gr.Interface(
 
46
  )
47
 
48
  # Update the output boxes with the generated text and image
49
+ def update_output(text, image_url):
50
+ # Get the current text in the output box
51
+ current_text = text_output.value
52
+ # Add the new text to the current text
53
+ new_text = current_text + "\n\n" + text
54
+ # Update the text output box with the new text
55
+ text_output.update(new_text)
56
 
57
+ iface.interface_result_hooks = [update_output]
58
 
59
  # Launch the interface
60
+ iface.launch()