CoolFace
Apppublic

F4illed/Kurdish-Video-Sub

sourceHugging Facemitupdated 9mo agoView on Hugging Face
0likes
app.py160 linesDownload Raw Back to root
1import gradio as gr2from huggingface_hub import InferenceClient3from deep_translator import GoogleTranslator4import os5 6# HF Token Setup7hf_token = os.getenv("HF_TOKEN")8client = InferenceClient("Qwen/Qwen2.5-72B-Instruct", token=hf_token)9 10def respond(message, history, language_mode):11    # History Cleaner (List Only)12    cleaned_history = []13    if history:14        for item in history:15            if isinstance(item, (list, tuple)) and len(item) == 2:16                cleaned_history.append(item)17    history = cleaned_history18    19    history.append([message, ""])20    21    # English Mode22    if language_mode == "English ๐Ÿ‡บ๐Ÿ‡ธ":23        system_prompt = "You are F4illed AI. Identity: IT Student, Reverse Engineer from Soran. Created by F4illed."24        messages = [{"role": "system", "content": system_prompt}]25        26        for user_msg, bot_msg in history[:-1]:27            messages.append({"role": "user", "content": str(user_msg)})28            messages.append({"role": "assistant", "content": str(bot_msg)})29        messages.append({"role": "user", "content": message})30        31        try:32            stream = client.chat_completion(messages, max_tokens=2048, stream=True, temperature=0.7)33            response_text = ""34            for chunk in stream:35                if chunk.choices and chunk.choices[0].delta.content:36                    response_text += chunk.choices[0].delta.content37                    history[-1][1] = response_text38                    yield history, ""39        except Exception as e:40            history[-1][1] = f"Error: {str(e)}"41            yield history, ""42 43    # Kurdish Mode44    else: 45        try:46            translated_input = GoogleTranslator(source='auto', target='en').translate(message)47        except:48            translated_input = message 49        50        system_prompt = "You are F4illed AI. Provide helpful, direct answers. F4illed is creator."51        messages = [{"role": "system", "content": system_prompt}]52        messages.append({"role": "user", "content": translated_input})53 54        history[-1][1] = "โณ ..."55        yield history, ""56        57        try:58            response = client.chat_completion(messages, max_tokens=2048, stream=False, temperature=0.5)59            full_english_response = response.choices[0].message.content60            61            final_kurdish_response = GoogleTranslator(source='en', target='ckb').translate(full_english_response)62            final_kurdish_response = final_kurdish_response.replace("F4illed", "(F4illed)")63            64            history[-1][1] = final_kurdish_response65            yield history, ""66        except Exception as e:67            history[-1][1] = f"Error: {str(e)}"68            yield history, ""69 70# ---------------------------------------------------------71# Custom CSS (Seamless Dark Theme)72# ---------------------------------------------------------73custom_css = """74/* Background and Container Reset */75body, .gradio-container {76    background-color: #050505 !important;77    background-image: radial-gradient(at 0% 0%, hsla(253,16%,7%,1) 0, transparent 50%), radial-gradient(at 50% 0%, hsla(225,39%,30%,1) 0, transparent 50%), radial-gradient(at 100% 0%, hsla(339,49%,30%,1) 0, transparent 50%);78    border: none !important;79}80 81/* Header Styling */82#custom-header {83    text-align: center;84    padding: 20px;85    background: rgba(255, 255, 255, 0.05);86    backdrop-filter: blur(10px);87    border-radius: 0 0 25px 25px;88    border-bottom: 1px solid rgba(255, 255, 255, 0.1);89    box-shadow: 0 10px 30px rgba(0,0,0,0.5);90    margin-bottom: 20px;91}92 93/* Chatbot Area Removal of White Background */94.wrap, .contain, .gradio-container-3-50-2 .prose {95    background: transparent !important;96    border: none !important;97    box-shadow: none !important;98}99#chatbot-component {100    background: transparent !important;101    border: none !important;102    box-shadow: none !important;103}104 105/* Messages Styling */106.message.bot {107    background: rgba(30, 41, 59, 0.9) !important;108    border: 1px solid rgba(255, 255, 255, 0.1) !important;109    border-radius: 0 20px 20px 20px !important;110    color: #e2e8f0 !important;111}112.message.user {113    background: linear-gradient(135deg, #2563eb, #7c3aed) !important;114    border: none !important;115    border-radius: 20px 20px 0 20px !important;116    color: white !important;117}118 119/* Input Area Styling */120textarea {121    background-color: rgba(17, 24, 39, 0.8) !important;122    border: 1px solid #374151 !important;123    color: white !important;124}125textarea:focus {126    border-color: #60a5fa !important;127    box-shadow: 0 0 10px rgba(96, 165, 250, 0.3) !important;128}129 130/* Footer Removal */131footer {display: none !important;}132"""133 134# App Layout135with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", neutral_hue="slate"), css=custom_css) as demo:136    137    with gr.Row(elem_id="custom-header"):138        gr.Markdown("# โšก F4illed AI")139 140    # ID added to target CSS removal of background141    chatbot = gr.Chatbot(label="Chat", show_label=False, height=500, elem_id="chatbot-component")142 143    with gr.Row():144        msg = gr.Textbox(show_label=False, placeholder="Type your message...", scale=8, container=False)145        send_btn = gr.Button("Send / ู†ุงุฑุฏู† ๐Ÿš€", scale=1, variant="primary")146 147    with gr.Row(elem_id="lang-row"):148        language_mode = gr.Radio(149            ["Kurdish (Sorani) ๐Ÿ‡น๐Ÿ‡ฏ", "English ๐Ÿ‡บ๐Ÿ‡ธ"], 150            label="Language / ุฒู…ุงู†",151            show_label=True,152            value="Kurdish (Sorani) ๐Ÿ‡น๐Ÿ‡ฏ"153        )154 155    msg.submit(respond, [msg, chatbot, language_mode], [chatbot, msg])156    send_btn.click(respond, [msg, chatbot, language_mode], [chatbot, msg])157 158if __name__ == "__main__":159    demo.queue().launch()160