File size: 3,068 Bytes
4a35942
4a7d211
4a35942
 
54e32c3
f79c98e
1e24c34
 
 
f79c98e
1e24c34
 
4a7d211
f79c98e
1e24c34
f79c98e
4a35942
 
f79c98e
4a35942
074fe2f
f79c98e
 
 
8474df8
f79c98e
074fe2f
1e24c34
4a7d211
f79c98e
4a35942
1e24c34
 
074fe2f
4a35942
 
1e24c34
4a35942
 
 
074fe2f
1e24c34
4a35942
f79c98e
4a35942
 
 
 
f79c98e
 
4a35942
 
1e24c34
 
 
 
 
 
 
 
 
4a7d211
f79c98e
1e24c34
 
 
 
 
4a35942
54e32c3
4a35942
 
1e24c34
 
4a35942
f79c98e
4a35942
1e24c34
4a35942
54e32c3
f79c98e
4a35942
1
2
3
4
5
6
7
8
9
10
11
12
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import requests
import gradio as gr
from openai import OpenAI

# 🔑 API key-г environment variable-аас уншина
openai_api_key = os.getenv("OPENAI_API_KEY")
gemini_api_key = os.getenv("GEMINI_API_KEY")

# Баталгаажуулах
print("OPENAI_API_KEY =", openai_api_key)
print("GEMINI_API_KEY =", gemini_api_key)

# OpenAI client
if openai_api_key is None:
    raise ValueError("⚠️ OPENAI_API_KEY тохируулна уу!")
client = OpenAI(api_key=openai_api_key)

# ChatGPT (gpt-5) хариу
def chatgpt_response(prompt):
    try:
        response = client.responses.create(
            model="gpt-5",
            input=prompt
        )
        return response.output_text
    except Exception as e:
        return f"⚠️ ChatGPT error: {e}"

# Gemini хариу
def gemini_response(prompt):
    if gemini_api_key is None:
        return "⚠️ GEMINI_API_KEY тохируулаагүй байна!"
    try:
        url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key={gemini_api_key}"
        headers = {"Content-Type": "application/json"}
        data = {"contents": [{"parts": [{"text": prompt}]}]}
        res = requests.post(url, headers=headers, json=data)
        res_json = res.json()
        return res_json["candidates"][0]["content"]["parts"][0]["text"]
    except Exception as e:
        return f"⚠️ Gemini error: {e}"

# Fusion logic (ChatGPT quota дууссан үед Gemini fallback)
def fusion_ai(prompt):
    gpt_reply = chatgpt_response(prompt)
    gemini_reply = gemini_response(prompt)

    if "ChatGPT error" in gpt_reply.lower():
        return f"⚠️ ChatGPT quota дууссан тул Gemini хариу:\n\n{gemini_reply}"

    return f"""
<div style="background-color:#0d1117; padding:20px; border-radius:10px; color:#e6edf3; font-family:Segoe UI">
    <h3>🧩 <span style="color:#00d9ff">Fusion Summary</span></h3>
    <p><b>ChatGPT 🧠:</b> {gpt_reply}</p>
    <p><b>Gemini 🌐:</b> {gemini_reply}</p>
    <hr style="border:1px solid #222;">
    <h4>✨ <span style="color:#9b59b6">ZeppFusion Combined Insight:</span></h4>
    <p>{gpt_reply if len(gpt_reply) > len(gemini_reply) else gemini_reply}</p>
</div>
"""

# Gradio Interface
css = """
.gradio-container {background-color: #0d1117 !important; color: #e6edf3;}
h1, h3, h4, label {color: #00d9ff !important;}
textarea, input {background-color:#161b22 !important; color:#fff !important; border-radius:10px;}
button {background-color:#00d9ff !important; color:#000 !important; font-weight:bold; border-radius:10px;}
"""

app = gr.Interface(
    fn=fusion_ai,
    inputs=gr.Textbox(label="🗨️ Та асуултаа бичнэ үү", placeholder="Жишээ нь: AI гэж юу вэ?"),
    outputs=gr.HTML(label="💡 ZeppFusion AI-ийн хариулт"),
    title="🚀 ZeppFusion AI",
    description="ChatGPT (gpt-5) 🧠 + Gemini 🌐 хослуулсан Fusion AI chatbot — Where Intelligence Unites.",
    theme="soft",
    css=css,
)

if _name_ == "_main_":
    app.launch()