lab2 / app.py
Filip
fix loading ui
b03e00d
raw
history blame
3.11 kB
import gradio as gr
from llama_cpp import Llama
from huggingface_hub import hf_hub_download
# Global variable to track model loading status
model = None
def load_model():
repo_id = "forestav/gguf_lora_model"
model_file = "unsloth.F16.gguf"
local_path = hf_hub_download(
repo_id=repo_id,
filename=model_file
)
print(f"Loading model from: {local_path}")
model = Llama(
model_path=local_path,
n_ctx=2048,
n_threads=8
)
return model
def generate_career_response(message, history):
if model is None:
return "Model is still loading. Please wait..."
enhanced_prompt = f"""As a career development advisor, help the user with their professional growth.
Consider:
1. Skill development opportunities
2. Industry trends
3. Practical next steps
4. Resources and learning paths
User Query: {message}
Provide a structured response with actionable advice."""
response = model.create_chat_completion(
messages=[
{"role": "system", "content": "You are a professional career advisor focused on providing practical, actionable guidance for career development."},
{"role": "user", "content": enhanced_prompt}
],
max_tokens=512,
temperature=0.7,
top_p=0.95,
)
return response['choices'][0]['message']['content']
# Create the interface first
demo = gr.ChatInterface(
fn=generate_career_response,
title="Career Growth Navigator πŸš€",
description="""Your AI career development partner. Ask about:
β€’ Skill development paths
β€’ Career transition strategies
β€’ Industry trends and opportunities
β€’ Resume and interview preparation
β€’ Professional networking advice
β€’ Work-life balance
Let's shape your professional future together!""",
examples=[
"I'm a software developer wanting to transition into AI/ML. What skills should I focus on?",
"How can I improve my leadership skills in my current role?",
"What are the key trends in digital marketing I should be aware of?",
"I want to start freelancing in web development. Where should I begin?",
"How can I negotiate a promotion in my current position?"
]
)
# Create loading interface
with gr.Blocks() as loading_demo:
gr.Markdown("# Loading Career Growth Navigator πŸš€")
with gr.Row():
loading_msg = gr.Markdown("⏳ The model is currently loading. Please wait...")
if __name__ == "__main__":
# Start with loading interface
loading_demo.queue()
loading_demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=False,
prevent_thread_lock=True
)
# Load the model
print("Starting model loading...")
model = load_model()
print("Model loaded successfully!")
# Close loading interface and launch main interface
loading_demo.close()
demo.queue()
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=False
)