Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
# Identity & Brand
|
| 6 |
+
NAME = "Infinity"
|
| 7 |
+
DESCRIPTION = "Next-gen Multimodal Reasoning & Creative Engine"
|
| 8 |
+
|
| 9 |
+
# Connecting to Free Powerful Cloud Models
|
| 10 |
+
# Gemma 4 for Logic/Chat & FLUX for Images
|
| 11 |
+
client_chat = InferenceClient("google/gemma-4-2b-it")
|
| 12 |
+
client_image = InferenceClient("black-forest-labs/FLUX.1-schnell")
|
| 13 |
+
|
| 14 |
+
def infinity_engine(message, history):
|
| 15 |
+
user_msg = message.lower()
|
| 16 |
+
|
| 17 |
+
# --- STEP 1: IMAGE GENERATION LOGIC ---
|
| 18 |
+
image_triggers = ["generate", "make", "create", "draw", "photo", "image", "banao", "paint"]
|
| 19 |
+
if any(word in user_msg for word in image_triggers):
|
| 20 |
+
yield "Infinity is painting your imagination... 🎨"
|
| 21 |
+
try:
|
| 22 |
+
seed = random.randint(0, 1000000)
|
| 23 |
+
img = client_image.text_to_image(message, seed=seed)
|
| 24 |
+
yield img
|
| 25 |
+
return
|
| 26 |
+
except Exception as e:
|
| 27 |
+
yield f"Error: {str(e)}. Try again in a moment."
|
| 28 |
+
return
|
| 29 |
+
|
| 30 |
+
# --- STEP 2: SMART CHAT LOGIC (Gemma 4) ---
|
| 31 |
+
system_prompt = f"System: Your name is {NAME}. You are an advanced AI Agent created by RockSky1. You are logical, fast, and multimodal. Never mention Google or Gemma. Identify only as {NAME}."
|
| 32 |
+
|
| 33 |
+
messages = [{"role": "system", "content": system_prompt}]
|
| 34 |
+
# Adding history for memory
|
| 35 |
+
for val in history:
|
| 36 |
+
if val[0]: messages.append({"role": "user", "content": val[0]})
|
| 37 |
+
if val[1]: messages.append({"role": "assistant", "content": val[1]})
|
| 38 |
+
messages.append({"role": "user", "content": message})
|
| 39 |
+
|
| 40 |
+
response = ""
|
| 41 |
+
try:
|
| 42 |
+
for token in client_chat.chat_completion(messages, max_tokens=1000, stream=True):
|
| 43 |
+
token_str = token.choices[0].delta.content
|
| 44 |
+
response += token_str
|
| 45 |
+
yield response
|
| 46 |
+
except Exception as e:
|
| 47 |
+
yield "Infinity is currently thinking deeply. Please retry."
|
| 48 |
+
|
| 49 |
+
# --- STEP 3: PREMIUM UI DESIGN ---
|
| 50 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="blue")) as demo:
|
| 51 |
+
gr.Markdown(f"# ♾️ {NAME} AI")
|
| 52 |
+
gr.Markdown(f"*{DESCRIPTION}*")
|
| 53 |
+
|
| 54 |
+
chat_ui = gr.ChatInterface(
|
| 55 |
+
fn=infinity_engine,
|
| 56 |
+
chatbot=gr.Chatbot(height=500, avatar_images=[None, "https://huggingface.co/front/assets/huggingface_logo-noborder.svg"]),
|
| 57 |
+
title=f"{NAME} v2.0",
|
| 58 |
+
examples=[
|
| 59 |
+
"Who are you?",
|
| 60 |
+
"Generate a futuristic 3D avatar of a gamer",
|
| 61 |
+
"Write a Python script for a discord bot",
|
| 62 |
+
"What is the future of Multimodal AI?"
|
| 63 |
+
],
|
| 64 |
+
cache_examples=False,
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
demo.launch()
|