Spaces:
Runtime error
Runtime error
.env
#1
by
sadsawq - opened
app.py
CHANGED
|
@@ -1,6 +1,129 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// FLOWER AI Uygulaması - Grok klonu
|
| 2 |
+
// Framework: React + Tailwind + Hugging Face API
|
| 3 |
+
// Kod tam sayfa layout, model seçimi ve konuşma sistemi ile hazırlandı
|
| 4 |
|
| 5 |
+
import React, { useState, useEffect, useRef } from "react";
|
| 6 |
+
import { InferenceClient } from "@huggingface/inference";
|
| 7 |
+
import { Textarea } from "@/components/ui/textarea";
|
| 8 |
+
import { Button } from "@/components/ui/button";
|
| 9 |
+
import { Card } from "@/components/ui/card";
|
| 10 |
+
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
| 11 |
+
import { Mic, Paperclip, Sparkles, Brain } from "lucide-react";
|
| 12 |
+
import Editor from "@monaco-editor/react";
|
| 13 |
|
| 14 |
+
const client = new InferenceClient(process.env.NEXT_PUBLIC_HF_TOKEN);
|
| 15 |
+
|
| 16 |
+
const models = {
|
| 17 |
+
"Flower Chat": "openai/gpt-oss-20b",
|
| 18 |
+
"Flower Coder": "Qwen/Qwen3-Coder-30B-A3B-Instruct",
|
| 19 |
+
"Flower MULTI": "moonshotai/Kimi-K2-Instruct"
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
export default function FlowerApp() {
|
| 23 |
+
const [model, setModel] = useState("Flower Chat");
|
| 24 |
+
const [input, setInput] = useState("");
|
| 25 |
+
const [messages, setMessages] = useState([]);
|
| 26 |
+
const [thinking, setThinking] = useState(false);
|
| 27 |
+
const [codeOutput, setCodeOutput] = useState("");
|
| 28 |
+
const chatEndRef = useRef(null);
|
| 29 |
+
|
| 30 |
+
const sendMessage = async () => {
|
| 31 |
+
if (!input.trim()) return;
|
| 32 |
+
const userMessage = { role: "user", content: input };
|
| 33 |
+
setMessages((prev) => [...prev, userMessage]);
|
| 34 |
+
setInput("");
|
| 35 |
+
setThinking(true);
|
| 36 |
+
|
| 37 |
+
try {
|
| 38 |
+
const response = await client.chatCompletion({
|
| 39 |
+
provider: "auto",
|
| 40 |
+
model: models[model],
|
| 41 |
+
messages: [...messages, userMessage]
|
| 42 |
+
});
|
| 43 |
+
const reply = response.choices[0].message;
|
| 44 |
+
setMessages((prev) => [...prev, reply]);
|
| 45 |
+
if (model === "Flower Coder") setCodeOutput(reply.content);
|
| 46 |
+
} catch (err) {
|
| 47 |
+
setMessages((prev) => [...prev, { role: "system", content: "❌ Hata: " + err.message }]);
|
| 48 |
+
}
|
| 49 |
+
setThinking(false);
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
useEffect(() => {
|
| 53 |
+
chatEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
| 54 |
+
}, [messages]);
|
| 55 |
+
|
| 56 |
+
return (
|
| 57 |
+
<div className="flex h-screen w-screen overflow-hidden">
|
| 58 |
+
{/* Sidebar */}
|
| 59 |
+
<div className="w-[280px] bg-white flex flex-col justify-between p-4 border-r">
|
| 60 |
+
<div>
|
| 61 |
+
<Button className="w-full mb-4">+ Yeni Sohbet</Button>
|
| 62 |
+
{/* Geçmiş Sohbetler */}
|
| 63 |
+
</div>
|
| 64 |
+
<div className="flex flex-col gap-2">
|
| 65 |
+
<Button variant="ghost">🖼 Resmi Düzenle</Button>
|
| 66 |
+
<Button variant="ghost">📰 Son Dakika Haberleri</Button>
|
| 67 |
+
<Button variant="ghost">🎭 Kişilikler</Button>
|
| 68 |
+
</div>
|
| 69 |
+
</div>
|
| 70 |
+
|
| 71 |
+
{/* Ana Alan */}
|
| 72 |
+
<div className="flex-1 flex flex-col relative bg-gradient-to-b from-[--flower11] to-[--flower14]">
|
| 73 |
+
{/* Üst Logo */}
|
| 74 |
+
<div className="text-center text-4xl font-bold py-6">Flower</div>
|
| 75 |
+
|
| 76 |
+
{/* Mesajlar */}
|
| 77 |
+
<div className="flex-1 overflow-y-auto p-6 space-y-4">
|
| 78 |
+
{messages.map((msg, i) => (
|
| 79 |
+
<Card key={i} className={`p-4 w-fit ${msg.role === "user" ? "ml-auto bg-flower3" : "mr-auto bg-white"}`}>
|
| 80 |
+
{msg.content}
|
| 81 |
+
</Card>
|
| 82 |
+
))}
|
| 83 |
+
{thinking && (
|
| 84 |
+
<Card className="mr-auto bg-white p-4 animate-pulse">🤔 Düşünüyor...</Card>
|
| 85 |
+
)}
|
| 86 |
+
<div ref={chatEndRef} />
|
| 87 |
+
</div>
|
| 88 |
+
|
| 89 |
+
{/* Alt Giriş Alanı */}
|
| 90 |
+
<div className="p-4 border-t flex items-center gap-2">
|
| 91 |
+
<Paperclip className="w-5 h-5" />
|
| 92 |
+
<Button variant="outline" className="text-sm">DeepSearch</Button>
|
| 93 |
+
<Button variant="outline" className="text-sm">Think</Button>
|
| 94 |
+
<Textarea
|
| 95 |
+
value={input}
|
| 96 |
+
onChange={(e) => setInput(e.target.value)}
|
| 97 |
+
placeholder="Ne bilmek istiyorsun?"
|
| 98 |
+
className="flex-1 resize-none h-[56px] rounded-full border px-4 py-2 text-[16px]"
|
| 99 |
+
/>
|
| 100 |
+
<DropdownMenu>
|
| 101 |
+
<DropdownMenuTrigger asChild>
|
| 102 |
+
<Button variant="outline">{model} ▼</Button>
|
| 103 |
+
</DropdownMenuTrigger>
|
| 104 |
+
<DropdownMenuContent>
|
| 105 |
+
{Object.keys(models).map((m) => (
|
| 106 |
+
<DropdownMenuItem key={m} onSelect={() => setModel(m)}>
|
| 107 |
+
{model === m ? "●" : "○"} {m}
|
| 108 |
+
</DropdownMenuItem>
|
| 109 |
+
))}
|
| 110 |
+
</DropdownMenuContent>
|
| 111 |
+
</DropdownMenu>
|
| 112 |
+
<Mic className="w-5 h-5" />
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
|
| 116 |
+
{/* Sağ Kod Paneli */}
|
| 117 |
+
{model === "Flower Coder" && (
|
| 118 |
+
<div className="w-[400px] bg-white border-l p-4 overflow-y-auto">
|
| 119 |
+
<Editor
|
| 120 |
+
height="100%"
|
| 121 |
+
defaultLanguage="javascript"
|
| 122 |
+
defaultValue={codeOutput || "// Kod burada görüntülenecek..."}
|
| 123 |
+
theme="vs-light"
|
| 124 |
+
/>
|
| 125 |
+
</div>
|
| 126 |
+
)}
|
| 127 |
+
</div>
|
| 128 |
+
);
|
| 129 |
+
}
|