import gradio as gr from llama_cpp import Llama from huggingface_hub import hf_hub_download import os # --- MODEL DOWNLOAD (Llama-3-8B) --- repo_id = "bartowski/Meta-Llama-3-8B-Instruct-GGUF" filename = "Meta-Llama-3-8B-Instruct-Q4_K_M.gguf" model_path = "ai.gguf" if not os.path.exists(model_path): print("Downloading International Llama-3 model...") downloaded_path = hf_hub_download(repo_id=repo_id, filename=filename) os.rename(downloaded_path, model_path) # --- LOAD MODEL --- llm = Llama(model_path=model_path, n_ctx=4096, n_threads=4, chat_format="llama-3") def sam_chat(message, history): messages = [{"role": "system", "content": "You are SAM, a VIP International AI developed by Samahir Studio Production. Provide professional and sharp answers."}] for human, assistant in history: messages.append({"role": "user", "content": human}) messages.append({"role": "assistant", "content": assistant}) messages.append({"role": "user", "content": message}) response = llm.create_chat_completion(messages=messages, max_tokens=1024, stream=False) return response['choices'][0]['message']['content'] # --- MODERN UI DESIGN (ChatGPT Style) --- custom_css = """ .gradio-container { background-color: #ffffff !important; font-family: 'Inter', sans-serif !important; } .message-row.user { background-color: #f7f7f8 !important; border-bottom: 1px solid #e5e5e5; } .message-row.bot { background-color: #ffffff !important; border-bottom: 1px solid #e5e5e5; } #title { text-align: center; margin-bottom: 20px; color: #333; } .dark .gradio-container { background-color: #343541 !important; color: white; } """ with gr.Blocks(css=custom_css, theme=gr.themes.Default(spacing_size="sm", radius_size="lg")) as demo: gr.Markdown("# 💎 SAM INTERNATIONAL AI", elem_id="title") gr.Markdown("#### Developed by **Samahir Studio Production**", elem_id="title") # API access is enabled by default in Gradio ChatInterface chat = gr.ChatInterface( fn=sam_chat, type="messages", description="International Level AI ready for your commands.", ) if __name__ == "__main__": # api_name="chat" helps identify the endpoint for external apps demo.launch(server_name="0.0.0.0", server_port=7860, show_api=True)