Vishwas1 commited on
Commit
e0f1cbd
·
verified ·
1 Parent(s): 46a2003

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +77 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,79 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from huggingface_hub import hf_hub_download
3
+ import os
4
 
5
+ # --- CONFIGURATION ---
6
+ MODEL_REPO = "bharatgenai/Param2-17B-A2.4B-Thinking"
7
+ # Note: Replace this with the actual GGUF repo once it is confirmed live
8
+ GGUF_REPO = "DarkWolfX/Param2-17B-A2.4B-Thinking-GGUF"
9
+ GGUF_FILE = "param2-thinking-q4_k_m.gguf"
10
+
11
+ # --- UI SETUP ---
12
+ st.set_page_config(page_title="Param2 Multilingual Chat", layout="centered")
13
+ st.title("🇮🇳 Param2-17B Thinking Chatbot")
14
+
15
+ # Language Selection Dropdown
16
+ languages = [
17
+ "English", "Hindi", "Assamese", "Bengali", "Bodo", "Dogri", "Gujarati",
18
+ "Kannada", "Konkani", "Kashmiri", "Maithili", "Malayalam", "Manipuri",
19
+ "Marathi", "Nepali", "Oriya", "Punjabi", "Sanskrit", "Santali",
20
+ "Sindhi", "Tamil", "Telugu", "Urdu"
21
+ ]
22
+ selected_lang = st.selectbox("Select Response Language:", languages)
23
+
24
+ # --- MODEL LOADING LOGIC ---
25
+ @st.cache_resource
26
+ def load_model():
27
+ try:
28
+ # 1. Check if GGUF exists and download
29
+ model_path = hf_hub_download(repo_id=GGUF_REPO, filename=GGUF_FILE)
30
+
31
+ # 2. Initialize llama-cpp (Optimized for CPU)
32
+ from llama_cpp import Llama
33
+ llm = Llama(
34
+ model_path=model_path,
35
+ n_ctx=4096,
36
+ n_threads=8, # Optimized for your 8 vCPU Space
37
+ )
38
+ return llm
39
+ except Exception as e:
40
+ return f"Error: GGUF model not found or incompatible. {str(e)}"
41
+
42
+ # Attempt to load
43
+ llm = load_model()
44
+
45
+ if isinstance(llm, str):
46
+ st.error(llm)
47
+ st.info("The GGUF version of this model might not be available yet. Please check back later!")
48
+ else:
49
+ # --- CHAT INTERFACE ---
50
+ if "messages" not in st.session_state:
51
+ st.session_state.messages = []
52
+
53
+ for message in st.session_state.messages:
54
+ with st.chat_message(message["role"]):
55
+ st.markdown(message["content"])
56
+
57
+ if prompt := st.chat_input("Ask something..."):
58
+ st.session_state.messages.append({"role": "user", "content": prompt})
59
+ with st.chat_message("user"):
60
+ st.markdown(prompt)
61
+
62
+ with st.chat_message("assistant"):
63
+ # System Prompt Injection for Language
64
+ system_instruction = f"You are a helpful assistant. You must respond ONLY in {selected_lang}."
65
+ full_prompt = f"<|system|>\n{system_instruction}\n<|user|>\n{prompt}\n<|assistant|>\n"
66
+
67
+ # Generate response
68
+ response_container = st.empty()
69
+ full_response = ""
70
+
71
+ # Stream the response for a better UI feel
72
+ for chunk in llm(full_prompt, max_tokens=1024, stream=True):
73
+ text = chunk["choices"][0]["text"]
74
+ full_response += text
75
+ response_container.markdown(full_response + "▌")
76
+
77
+ response_container.markdown(full_response)
78
+
79
+ st.session_state.messages.append({"role": "assistant", "content": full_response})