JustForFunn commited on
Commit
d5f9903
·
1 Parent(s): 038ae24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -22,21 +22,30 @@ def generate_text(prompt):
22
  return response.choices[0].text.strip()
23
 
24
  # Define a function to generate image from text prompt using the loaded model
25
- def process_prompt(prompt):
26
- prompt += ", in " + model_prefix
27
  image_return = model(prompt)
28
  return image_return
29
 
 
30
  interface = gradio.Interface(
31
  fn=process_prompt,
32
  inputs=["text", gradio.inputs.Textbox(label="Enter prompt")],
33
  outputs=[
34
- "image", gradio.outputs.Image(label="Generated Image", type="pil"),
35
  "text", gradio.outputs.Textbox(label="Generated Text")
36
  ],
37
  title="AlStable Text-to-Image",
38
  description="Generates an image from a text prompt and provides text response.",
39
  )
40
 
 
 
 
 
 
 
 
 
41
  # Launch the interface
42
  interface.launch()
 
22
  return response.choices[0].text.strip()
23
 
24
  # Define a function to generate image from text prompt using the loaded model
25
+ def process_prompt(text):
26
+ prompt = text + ", in " + model_prefix
27
  image_return = model(prompt)
28
  return image_return
29
 
30
+ # Create Gradio interface
31
  interface = gradio.Interface(
32
  fn=process_prompt,
33
  inputs=["text", gradio.inputs.Textbox(label="Enter prompt")],
34
  outputs=[
35
+ "image", gradio.outputs.Image(label="Generated Image", type="numpy"),
36
  "text", gradio.outputs.Textbox(label="Generated Text")
37
  ],
38
  title="AlStable Text-to-Image",
39
  description="Generates an image from a text prompt and provides text response.",
40
  )
41
 
42
+ # Add a callback function to update the "Generated Text" output box based on the input text
43
+ def update_output_text(inp):
44
+ response_text = generate_text(inp)
45
+ interface.set_output_text(response_text)
46
+
47
+ # Set the callback function for the input textbox
48
+ interface.inputs[0].set_property("on_input", update_output_text)
49
+
50
  # Launch the interface
51
  interface.launch()