File size: 1,943 Bytes
4a35942
4a7d211
4a35942
54e32c3
e632292
1e24c34
e632292
 
1e24c34
e632292
4a35942
074fe2f
4a35942
 
1e24c34
4a35942
 
 
074fe2f
1e24c34
4a35942
e632292
 
 
 
 
4a7d211
e632292
1e24c34
 
 
 
 
e632292
 
4a35942
54e32c3
e632292
a9c0001
e632292
a9c0001
 
 
 
e632292
a9c0001
e632292
 
54e32c3
bf01995
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
import os
import requests
import gradio as gr

# Gemini API key
gemini_api_key = os.getenv("GEMINI_API_KEY")
if gemini_api_key is None:
    raise ValueError("⚠️ GEMINI_API_KEY тохируулаагүй байна!")

# Gemini response function
def gemini_response(prompt):
    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}"

# Chat function with history
def chat(prompt, history=[]):
    reply = gemini_response(prompt)
    history.append((prompt, reply))
    return history, history

# Custom CSS for chat design
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;}
.gradio-chatbot-message.user {background-color:#0f2c54; color:#fff; border-radius:15px; padding:10px;}
.gradio-chatbot-message.bot {background-color:#1f1f1f; color:#00d9ff; border-radius:15px; padding:10px;}
"""

# Gradio interface
with gr.Blocks(css=css, theme=gr.themes.Soft()) as app:
    gr.Markdown("## 🚀 ZeppFusion AI — Gemini Chat Only")
    chatbot = gr.Chatbot()
    msg = gr.Textbox(placeholder="Таны асуулт...")
    clear = gr.Button("🗑️ Clear History")

    msg.submit(chat, [msg, chatbot], [chatbot, chatbot])
    
    # Clear button
    clear.click(lambda: [], None, chatbot)

if __name__ == "__main__":
    app.launch()