Vedika-AI commited on
Commit
b827b19
·
verified ·
1 Parent(s): db2e240

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -15,15 +15,14 @@ HEADERS = {
15
  }
16
 
17
  def generate_or_edit(prompt, input_image=None):
18
- # Flux API के लिए मानक payload स्ट्रक्चर
19
  payload = {
20
  "prompt": prompt,
21
- "aspect_ratio": "1:1",
22
- "seed": 42,
 
23
  "steps": 4
24
  }
25
 
26
- # अगर इमेज एडिटिंग के लिए है
27
  if input_image is not None:
28
  buffered = io.BytesIO()
29
  input_image.save(buffered, format="PNG")
@@ -35,19 +34,12 @@ def generate_or_edit(prompt, input_image=None):
35
  response.raise_for_status()
36
  result = response.json()
37
 
38
- # NVIDIA API क्'result' 'image' ें इमेजता है
39
- if "image" in result:
40
- image_data = base64.b64decode(result["image"])
41
- elif "output" in result and "image" in result["output"]:
42
- image_data = base64.b64decode(result["output"]["image"])
43
- else:
44
- return None
45
 
46
  return Image.open(io.BytesIO(image_data))
47
 
48
- except requests.exceptions.HTTPError as e:
49
- print(f"HTTP Error: {e.response.text}") # यहाँ असली एरर दिखेगा
50
- return None
51
  except Exception as e:
52
  print(f"Error: {e}")
53
  return None
@@ -62,4 +54,4 @@ with gr.Blocks() as demo:
62
 
63
  submit_btn.click(fn=generate_or_edit, inputs=[prompt_input, image_input], outputs=result_output)
64
 
65
- demo.launch()
 
15
  }
16
 
17
  def generate_or_edit(prompt, input_image=None):
 
18
  payload = {
19
  "prompt": prompt,
20
+ "width": 1024,
21
+ "height": 1024,
22
+ "seed": 0,
23
  "steps": 4
24
  }
25
 
 
26
  if input_image is not None:
27
  buffered = io.BytesIO()
28
  input_image.save(buffered, format="PNG")
 
34
  response.raise_for_status()
35
  result = response.json()
36
 
37
+ # अब हम सीधे उस स्ट्रक्का उपोग रह हैं ज आपन दिखया है
38
+ image_b64 = result["artifacts"][0]["base64"]
39
+ image_data = base64.b64decode(image_b64)
 
 
 
 
40
 
41
  return Image.open(io.BytesIO(image_data))
42
 
 
 
 
43
  except Exception as e:
44
  print(f"Error: {e}")
45
  return None
 
54
 
55
  submit_btn.click(fn=generate_or_edit, inputs=[prompt_input, image_input], outputs=result_output)
56
 
57
+ demo.launch(server_name="0.0.0.0", server_port=7860)