| import gradio as gr |
| from llama_cpp import Llama |
| from huggingface_hub import hf_hub_download |
| import os |
|
|
| |
| 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) |
|
|
| |
| 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'] |
|
|
| |
| 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") |
| |
| |
| chat = gr.ChatInterface( |
| fn=sam_chat, |
| type="messages", |
| description="International Level AI ready for your commands.", |
| ) |
|
|
| if __name__ == "__main__": |
| |
| demo.launch(server_name="0.0.0.0", server_port=7860, show_api=True) |