Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from ctransformers import AutoModelForCausalLM
|
| 3 |
+
|
| 4 |
+
# Title of the Chatbot
|
| 5 |
+
st.set_page_config(page_title="Prof. Cool AI - Phi-2 Chatbot", layout="centered")
|
| 6 |
+
st.title("🚀 Prof. Cool AI - Chatbot powered by Phi-2")
|
| 7 |
+
|
| 8 |
+
# Load Model
|
| 9 |
+
@st.cache_resource
|
| 10 |
+
def load_model():
|
| 11 |
+
return AutoModelForCausalLM.from_pretrained(
|
| 12 |
+
"TheBloke/Phi-2-GGUF",
|
| 13 |
+
model_file="phi-2.Q4_K_S.gguf", # Make sure this matches your downloaded model
|
| 14 |
+
model_type="phi",
|
| 15 |
+
gpu_layers=50 # Set to 0 for CPU
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
model = load_model()
|
| 19 |
+
st.success("✅ Model Loaded Successfully!")
|
| 20 |
+
|
| 21 |
+
# User Input
|
| 22 |
+
user_input = st.text_area("📝 Enter your question:", height=100)
|
| 23 |
+
|
| 24 |
+
if st.button("Ask Prof. Cool"):
|
| 25 |
+
if user_input.strip():
|
| 26 |
+
with st.spinner("Thinking... 🤖"):
|
| 27 |
+
response = model(user_input)
|
| 28 |
+
st.write("🧠 **Prof. Cool says:**")
|
| 29 |
+
st.success(response)
|
| 30 |
+
else:
|
| 31 |
+
st.warning("⚠️ Please enter a valid question.")
|