Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,31 +3,31 @@ import requests
|
|
| 3 |
import gradio as gr
|
| 4 |
from openai import OpenAI
|
| 5 |
|
| 6 |
-
# 🔑 API key-г environment variable-аас
|
| 7 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 8 |
gemini_api_key = os.getenv("GEMINI_API_KEY")
|
| 9 |
|
| 10 |
-
#
|
| 11 |
print("OPENAI_API_KEY =", openai_api_key)
|
| 12 |
print("GEMINI_API_KEY =", gemini_api_key)
|
| 13 |
|
| 14 |
-
#
|
| 15 |
if openai_api_key is None:
|
| 16 |
-
raise ValueError("⚠️ OPENAI_API_KEY
|
| 17 |
client = OpenAI(api_key=openai_api_key)
|
| 18 |
|
| 19 |
-
#
|
| 20 |
def chatgpt_response(prompt):
|
| 21 |
try:
|
| 22 |
-
|
| 23 |
-
model="gpt-
|
| 24 |
-
|
| 25 |
)
|
| 26 |
-
return
|
| 27 |
except Exception as e:
|
| 28 |
return f"⚠️ ChatGPT error: {e}"
|
| 29 |
|
| 30 |
-
#
|
| 31 |
def gemini_response(prompt):
|
| 32 |
if gemini_api_key is None:
|
| 33 |
return "⚠️ GEMINI_API_KEY тохируулаагүй байна!"
|
|
@@ -41,13 +41,13 @@ def gemini_response(prompt):
|
|
| 41 |
except Exception as e:
|
| 42 |
return f"⚠️ Gemini error: {e}"
|
| 43 |
|
| 44 |
-
#
|
| 45 |
def fusion_ai(prompt):
|
| 46 |
gpt_reply = chatgpt_response(prompt)
|
| 47 |
gemini_reply = gemini_response(prompt)
|
| 48 |
|
| 49 |
-
if "error" in gpt_reply.lower()
|
| 50 |
-
return "⚠️
|
| 51 |
|
| 52 |
return f"""
|
| 53 |
<div style="background-color:#0d1117; padding:20px; border-radius:10px; color:#e6edf3; font-family:Segoe UI">
|
|
@@ -60,7 +60,7 @@ def fusion_ai(prompt):
|
|
| 60 |
</div>
|
| 61 |
"""
|
| 62 |
|
| 63 |
-
#
|
| 64 |
css = """
|
| 65 |
.gradio-container {background-color: #0d1117 !important; color: #e6edf3;}
|
| 66 |
h1, h3, h4, label {color: #00d9ff !important;}
|
|
@@ -73,10 +73,10 @@ app = gr.Interface(
|
|
| 73 |
inputs=gr.Textbox(label="🗨️ Та асуултаа бичнэ үү", placeholder="Жишээ нь: AI гэж юу вэ?"),
|
| 74 |
outputs=gr.HTML(label="💡 ZeppFusion AI-ийн хариулт"),
|
| 75 |
title="🚀 ZeppFusion AI",
|
| 76 |
-
description="ChatGPT 🧠 + Gemini 🌐 хослуулсан Fusion AI chatbot — Where Intelligence Unites.",
|
| 77 |
theme="soft",
|
| 78 |
css=css,
|
| 79 |
)
|
| 80 |
|
| 81 |
-
if
|
| 82 |
app.launch()
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
from openai import OpenAI
|
| 5 |
|
| 6 |
+
# 🔑 API key-г environment variable-аас уншина
|
| 7 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 8 |
gemini_api_key = os.getenv("GEMINI_API_KEY")
|
| 9 |
|
| 10 |
+
# Баталгаажуулах
|
| 11 |
print("OPENAI_API_KEY =", openai_api_key)
|
| 12 |
print("GEMINI_API_KEY =", gemini_api_key)
|
| 13 |
|
| 14 |
+
# OpenAI client
|
| 15 |
if openai_api_key is None:
|
| 16 |
+
raise ValueError("⚠️ OPENAI_API_KEY тохируулна уу!")
|
| 17 |
client = OpenAI(api_key=openai_api_key)
|
| 18 |
|
| 19 |
+
# ChatGPT (gpt-5) хариу
|
| 20 |
def chatgpt_response(prompt):
|
| 21 |
try:
|
| 22 |
+
response = client.responses.create(
|
| 23 |
+
model="gpt-5",
|
| 24 |
+
input=prompt
|
| 25 |
)
|
| 26 |
+
return response.output_text
|
| 27 |
except Exception as e:
|
| 28 |
return f"⚠️ ChatGPT error: {e}"
|
| 29 |
|
| 30 |
+
# Gemini хариу
|
| 31 |
def gemini_response(prompt):
|
| 32 |
if gemini_api_key is None:
|
| 33 |
return "⚠️ GEMINI_API_KEY тохируулаагүй байна!"
|
|
|
|
| 41 |
except Exception as e:
|
| 42 |
return f"⚠️ Gemini error: {e}"
|
| 43 |
|
| 44 |
+
# Fusion logic (ChatGPT quota дууссан үед Gemini fallback)
|
| 45 |
def fusion_ai(prompt):
|
| 46 |
gpt_reply = chatgpt_response(prompt)
|
| 47 |
gemini_reply = gemini_response(prompt)
|
| 48 |
|
| 49 |
+
if "ChatGPT error" in gpt_reply.lower():
|
| 50 |
+
return f"⚠️ ChatGPT quota дууссан тул Gemini хариу:\n\n{gemini_reply}"
|
| 51 |
|
| 52 |
return f"""
|
| 53 |
<div style="background-color:#0d1117; padding:20px; border-radius:10px; color:#e6edf3; font-family:Segoe UI">
|
|
|
|
| 60 |
</div>
|
| 61 |
"""
|
| 62 |
|
| 63 |
+
# Gradio Interface
|
| 64 |
css = """
|
| 65 |
.gradio-container {background-color: #0d1117 !important; color: #e6edf3;}
|
| 66 |
h1, h3, h4, label {color: #00d9ff !important;}
|
|
|
|
| 73 |
inputs=gr.Textbox(label="🗨️ Та асуултаа бичнэ үү", placeholder="Жишээ нь: AI гэж юу вэ?"),
|
| 74 |
outputs=gr.HTML(label="💡 ZeppFusion AI-ийн хариулт"),
|
| 75 |
title="🚀 ZeppFusion AI",
|
| 76 |
+
description="ChatGPT (gpt-5) 🧠 + Gemini 🌐 хослуулсан Fusion AI chatbot — Where Intelligence Unites.",
|
| 77 |
theme="soft",
|
| 78 |
css=css,
|
| 79 |
)
|
| 80 |
|
| 81 |
+
if _name_ == "_main_":
|
| 82 |
app.launch()
|