BowoZZZ commited on
Commit
8b6e883
·
verified ·
1 Parent(s): a8df29c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -15,6 +15,9 @@ import uvicorn
15
  API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
16
  headers = {"Authorization": f"Bearer {os.getenv('HF')}"}
17
 
 
 
 
18
  # Function to query the Hugging Face API and generate an image
19
  def query(payload):
20
  response = requests.post(API_URL, headers=headers, json=payload)
@@ -39,7 +42,7 @@ api_app = FastAPI()
39
  def get_generated_image(text: str):
40
  """
41
  API endpoint that returns the generated image directly.
42
- Example: https://your-domain/?text=jokowi will eventually call this endpoint.
43
  """
44
  try:
45
  image = generate_image(text)
@@ -58,21 +61,18 @@ threading.Thread(target=run_api, daemon=True).start()
58
 
59
  # --- Streamlit UI ---
60
 
61
- # Use st.query_params (a property) to check for a query parameter.
62
  query_params = st.query_params
63
  prompt_from_url = query_params.get('text')
64
 
65
  if prompt_from_url:
66
  # If a query parameter "text" is present, assume this is an API request.
67
- # For API clients, we don't want to show UI elements like buttons.
68
- # Instead, we offer a clickable link or instructions so that they know
69
- # they can fetch the image directly from our FastAPI endpoint.
70
- st.write("A request with a text query parameter was detected. To get the raw image data, please use the API endpoint:")
71
- # Construct the API URL (adjust the host/domain and port as needed)
72
- api_endpoint = f"{st.experimental_get_url()[:-1]}/api?text={prompt_from_url}"
73
  st.write("API Endpoint:", api_endpoint)
74
 
75
- # Optionally, you can also show the generated image in the UI:
76
  image = generate_image(prompt_from_url)
77
  st.image(image, caption="Generated Image", use_container_width=True)
78
  else:
 
15
  API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
16
  headers = {"Authorization": f"Bearer {os.getenv('HF')}"}
17
 
18
+ # Define your base URL here (adjust this for your deployment)
19
+ BASE_URL = "https://bowozzz-gen.hf.space"
20
+
21
  # Function to query the Hugging Face API and generate an image
22
  def query(payload):
23
  response = requests.post(API_URL, headers=headers, json=payload)
 
42
  def get_generated_image(text: str):
43
  """
44
  API endpoint that returns the generated image directly.
45
+ Example: https://bowozzz-gen.hf.space/api?text=jokowi
46
  """
47
  try:
48
  image = generate_image(text)
 
61
 
62
  # --- Streamlit UI ---
63
 
64
+ # Use st.query_params to check for a query parameter.
65
  query_params = st.query_params
66
  prompt_from_url = query_params.get('text')
67
 
68
  if prompt_from_url:
69
  # If a query parameter "text" is present, assume this is an API request.
70
+ # Provide the API endpoint URL that returns raw image data.
71
+ st.write("A request with a text query parameter was detected. To get the raw image data, use the API endpoint below:")
72
+ api_endpoint = f"{BASE_URL}/api?text={prompt_from_url}"
 
 
 
73
  st.write("API Endpoint:", api_endpoint)
74
 
75
+ # Optionally, display the generated image in the UI:
76
  image = generate_image(prompt_from_url)
77
  st.image(image, caption="Generated Image", use_container_width=True)
78
  else: