Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,100 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
if
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
)
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# -------------------------
|
| 4 |
+
# SMART UNDERSTANDING LOGIC
|
| 5 |
+
# -------------------------
|
| 6 |
+
|
| 7 |
+
def detect_mode(user_text):
|
| 8 |
+
text = user_text.lower()
|
| 9 |
+
|
| 10 |
+
if any(k in text for k in ["upsc", "exam", "notes", "school", "college"]):
|
| 11 |
+
return "academic"
|
| 12 |
+
if any(k in text for k in ["instagram", "facebook", "dp", "profile", "post"]):
|
| 13 |
+
return "social"
|
| 14 |
+
if any(k in text for k in ["diagram", "flow", "map"]):
|
| 15 |
+
return "diagram"
|
| 16 |
+
return "general"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def build_prompt(user_text):
|
| 20 |
+
mode = detect_mode(user_text)
|
| 21 |
+
|
| 22 |
+
base_realism = (
|
| 23 |
+
"highly realistic, photorealistic image, "
|
| 24 |
+
"natural lighting, real human texture, "
|
| 25 |
+
"no cartoon, no fantasy, professional quality"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
if mode == "academic":
|
| 29 |
+
return (
|
| 30 |
+
f"{base_realism}, academic textbook style, "
|
| 31 |
+
f"exam-safe visual, subject based on: {user_text}"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
if mode == "social":
|
| 35 |
+
return (
|
| 36 |
+
f"{base_realism}, premium social media portrait, "
|
| 37 |
+
f"clean background, instagram facebook ready, "
|
| 38 |
+
f"based on: {user_text}"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
if mode == "diagram":
|
| 42 |
+
return (
|
| 43 |
+
f"clean academic diagram, simple design, "
|
| 44 |
+
f"clear labels, NCERT style, topic: {user_text}"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
return f"{base_realism}, based on: {user_text}"
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
NEGATIVE_PROMPT = (
|
| 51 |
+
"cartoon, anime, illustration, painting, fantasy, unreal, "
|
| 52 |
+
"plastic skin, blurry, distorted, watermark, text, logo"
|
| 53 |
)
|
| 54 |
|
| 55 |
+
# -------------------------
|
| 56 |
+
# IMAGE GENERATION FUNCTION
|
| 57 |
+
# -------------------------
|
| 58 |
+
def generate_image(user_text):
|
| 59 |
+
final_prompt = build_prompt(user_text)
|
| 60 |
+
|
| 61 |
+
# 🔴 यहां अपना MODEL / API call लगाना है
|
| 62 |
+
# image = model.generate(
|
| 63 |
+
# prompt=final_prompt,
|
| 64 |
+
# negative_prompt=NEGATIVE_PROMPT
|
| 65 |
+
# )
|
| 66 |
+
# return image
|
| 67 |
+
|
| 68 |
+
return None # placeholder (UI test के लिए)
|
| 69 |
+
|
| 70 |
+
# -------------------------
|
| 71 |
+
# GRADIO UI
|
| 72 |
+
# -------------------------
|
| 73 |
+
with gr.Blocks(title="Smart Text-to-Art AI") as demo:
|
| 74 |
+
gr.Markdown(
|
| 75 |
+
"""
|
| 76 |
+
## 🎓 Smart Text-to-Art AI Generator
|
| 77 |
+
बस लिखो, AI खुद समझेगा और realistic image बनाएगा
|
| 78 |
+
|
| 79 |
+
✔ Student Safe
|
| 80 |
+
✔ Social Media Ready
|
| 81 |
+
✔ No Cartoon / No Fantasy
|
| 82 |
+
"""
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
user_input = gr.Textbox(
|
| 86 |
+
label="आप क्या बनवाना चाहते हैं?",
|
| 87 |
+
placeholder="Example: UPSC ke liye raja ki realistic photo"
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
generate_btn = gr.Button("Generate Image")
|
| 91 |
+
output = gr.Image(label="Output", type="pil")
|
| 92 |
+
|
| 93 |
+
generate_btn.click(
|
| 94 |
+
fn=generate_image,
|
| 95 |
+
inputs=user_input,
|
| 96 |
+
outputs=output
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
demo.launch()
|