Spaces:
Running
Running
Commit
·
ff865cb
1
Parent(s):
ae90f46
Add application file
Browse files- app.py +38 -2
- requirements.txt +3 -0
app.py
CHANGED
|
@@ -1,4 +1,40 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 3 |
|
| 4 |
+
st.set_page_config(page_title="Chat with Qwen2.5-Omni-7B", layout="centered")
|
| 5 |
+
|
| 6 |
+
st.title("Chat with Qwen2.5-Omni-7B")
|
| 7 |
+
|
| 8 |
+
# Model name
|
| 9 |
+
model_name = "Qwen/Qwen2.5-Omni-7B"
|
| 10 |
+
|
| 11 |
+
# Prompt input
|
| 12 |
+
system_prompt = st.text_area("System Prompt", "You are a helpful assistant.", height=100)
|
| 13 |
+
user_input = st.text_input("Your Message", "")
|
| 14 |
+
|
| 15 |
+
# Temp & token sliders
|
| 16 |
+
temperature = st.slider("Temperature", 0.0, 1.0, 0.7)
|
| 17 |
+
max_tokens = st.slider("Max Tokens", 16, 1024, 256)
|
| 18 |
+
|
| 19 |
+
# Optional: Hugging Face token field (left empty for user)
|
| 20 |
+
hf_token = st.text_input("Hugging Face Token (optional)", type="password")
|
| 21 |
+
|
| 22 |
+
# Load model pipeline
|
| 23 |
+
@st.cache_resource
|
| 24 |
+
def load_pipeline():
|
| 25 |
+
return pipeline(
|
| 26 |
+
"text-generation",
|
| 27 |
+
model=model_name,
|
| 28 |
+
tokenizer=model_name,
|
| 29 |
+
use_auth_token=hf_token if hf_token else None,
|
| 30 |
+
device_map="auto"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
if user_input:
|
| 34 |
+
pipe = load_pipeline()
|
| 35 |
+
prompt = f"{system_prompt}
|
| 36 |
+
User: {user_input}
|
| 37 |
+
Assistant:"
|
| 38 |
+
response = pipe(prompt, temperature=temperature, max_new_tokens=max_tokens)[0]['generated_text']
|
| 39 |
+
st.markdown("**Response:**")
|
| 40 |
+
st.write(response.replace(prompt, ""))
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
transformers
|
| 3 |
+
torch
|