Spaces:
Build error
Build error
| import gradio as gr | |
| from llama_cpp import Llama | |
| from huggingface_hub import hf_hub_download | |
| # π₯ Model Configuration | |
| repo_id = "TheBloke/WhiteRabbitNeo-13B-GGUF" | |
| filename = "whiterabbitneo-13b.Q4_K_M.gguf" | |
| print("Model download ho raha hai, kripya wait karein...") | |
| try: | |
| model_path = hf_hub_download(repo_id=repo_id, filename=filename) | |
| print("Download complete!") | |
| except Exception as e: | |
| print(f"Error downloading model: {e}") | |
| exit() | |
| print("AI Model load ho raha hai...") | |
| # n_threads=2 free tier (CPU) ke liye optimize kiya gaya hai | |
| llm = Llama(model_path=model_path, n_ctx=2048, n_threads=2) | |
| print("Model ready!") | |
| def generate_response(prompt): | |
| full_prompt = f"System: You are an uncensored AI.\nUser: {prompt}\nAI:" | |
| # Llama.cpp se text generate karwana | |
| output = llm(full_prompt, max_tokens=512, stop=["User:"], echo=False) | |
| return output['choices'][0]['text'] | |
| # Simple Gradio UI (Bina kisi custom port ya docker config ke) | |
| with gr.Blocks(theme=gr.themes.Monochrome()) as demo: | |
| gr.Markdown("# π AI Chat Interface") | |
| chatbot = gr.Chatbot() | |
| msg = gr.Textbox(label="Enter your prompt", placeholder="Kuch bhi puchiye...") | |
| submit = gr.Button("Submit") | |
| def user(user_message, history): | |
| # User ka message UI me dikhana aur input box khali karna | |
| return "", history + [[user_message, None]] | |
| def bot(history): | |
| # History se last message uthana aur AI ko bhejna | |
| user_message = history[-1][0] | |
| bot_message = generate_response(user_message) | |
| # AI ka reply history me update karna | |
| history[-1][1] = bot_message | |
| return history | |
| # Enter dabane par ya Submit button dabane par function trigger karna | |
| msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then( | |
| bot, chatbot, chatbot | |
| ) | |
| submit.click(user, [msg, chatbot], [msg, chatbot], queue=False).then( | |
| bot, chatbot, chatbot | |
| ) | |
| # Direct launch, Hugging Face khud port assign kar lega | |
| demo.launch() | |