Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
|
| 5 |
+
# Download the model from Hugging Face
|
| 6 |
+
MODEL_REPO = "krishna195/new_model" # Replace with your repo ID
|
| 7 |
+
MODEL_FILE = "unsloth.Q4_K_M.gguf" # Replace with your file name
|
| 8 |
+
|
| 9 |
+
model_path = hf_hub_download(
|
| 10 |
+
repo_id=MODEL_REPO,
|
| 11 |
+
filename=MODEL_FILE,
|
| 12 |
+
cache_dir="./models" # Cache directory for storing the model
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# Load the LLaMA model
|
| 16 |
+
llm = Llama(model_path=model_path)
|
| 17 |
+
|
| 18 |
+
# Function for chatbot interaction
|
| 19 |
+
def chat_with_llama(user_input, history):
|
| 20 |
+
response = llm.create_chat_completion(
|
| 21 |
+
messages=[{"role": "user", "content": user_input}]
|
| 22 |
+
)
|
| 23 |
+
return response["choices"][0]["message"]["content"] # Extract response text
|
| 24 |
+
|
| 25 |
+
# Gradio UI
|
| 26 |
+
chatbot_ui = gr.ChatInterface(
|
| 27 |
+
fn=chat_with_llama,
|
| 28 |
+
title="LLaMA Chatbot",
|
| 29 |
+
description="Chat with a fine-tuned LLaMA model hosted on Hugging Face.",
|
| 30 |
+
theme="compact"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Launch Gradio app
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
chatbot_ui.launch()
|