Vedika-AI commited on
Commit
f3dddaf
·
verified ·
1 Parent(s): bd29162

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import base64
4
+ from PIL import Image
5
+ import io
6
+
7
+ # NVIDIA API Configuration
8
+ INVOKE_URL = "https://ai.api.nvidia.com/v1/genai/black-forest-labs/flux.2-klein-4b"
9
+ HEADERS = {
10
+ "Authorization": "Bearer $NVIDIA_API_KEY", # अपना API KEY यहाँ डालें या Environment Variable का उपयोग करें
11
+ "Accept": "application/json",
12
+ }
13
+
14
+ def generate_or_edit(prompt, input_image=None):
15
+ payload = {
16
+ "prompt": prompt,
17
+ "width": 1024,
18
+ "height": 1024,
19
+ "seed": 0,
20
+ "steps": 4
21
+ }
22
+
23
+ # अगर इमेज एडिटिंग है, तो इमेज को बेस64 में बदलें
24
+ if input_image is not None:
25
+ buffered = io.BytesIO()
26
+ input_image.save(buffered, format="PNG")
27
+ img_str = base64.b64encode(buffered.getvalue()).decode()
28
+ payload["image"] = [img_str]
29
+
30
+ response = requests.post(INVOKE_URL, headers=HEADERS, json=payload)
31
+ response.raise_for_status()
32
+
33
+ # यहाँ API रिस्पॉन्स से इमेज निकालें (API के स्ट्रक्चर के अनुसार)
34
+ result = response.json()
35
+ # मान लें कि रिस्पॉन्स में इमेज बेस64 में आ रही है
36
+ image_data = base64.b64decode(result["image"])
37
+ return Image.open(io.BytesIO(image_data))
38
+
39
+ # Gradio Interface
40
+ with gr.Blocks() as demo:
41
+ gr.Markdown("# Vedika AI - Image Editor & Generator")
42
+
43
+ with gr.Row():
44
+ with gr.Column():
45
+ prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
46
+ image_input = gr.Image(label="Upload Image (For Editing)", type="pil")
47
+ submit_btn = gr.Button("Generate / Edit")
48
+
49
+ with gr.Column():
50
+ result_output = gr.Image(label="Result")
51
+
52
+ submit_btn.click(fn=generate_or_edit, inputs=[prompt, image_input], outputs=result_output)
53
+
54
+ demo.launch()