choco-conoz commited on
Commit
06983e0
·
1 Parent(s): 30ddcd7

feat: text ux

Browse files
Files changed (5) hide show
  1. Dockerfile +6 -3
  2. poetry.lock +0 -0
  3. pyproject.toml +22 -0
  4. requirements.txt +3 -1
  5. src/streamlit_app.py +77 -38
Dockerfile CHANGED
@@ -1,5 +1,6 @@
1
- FROM python:3.9-slim
2
 
 
3
  WORKDIR /app
4
 
5
  RUN apt-get update && apt-get install -y \
@@ -9,10 +10,12 @@ RUN apt-get update && apt-get install -y \
9
  git \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
- COPY requirements.txt ./
13
  COPY src/ ./src/
14
 
15
- RUN pip3 install -r requirements.txt
 
 
 
16
 
17
  EXPOSE 8501
18
 
 
1
+ FROM python:3.11-slim
2
 
3
+ RUN pip3 install poetry=2.1.3
4
  WORKDIR /app
5
 
6
  RUN apt-get update && apt-get install -y \
 
10
  git \
11
  && rm -rf /var/lib/apt/lists/*
12
 
 
13
  COPY src/ ./src/
14
 
15
+ # COPY requirements.txt ./
16
+ # RUN pip3 install -r requirements.txt
17
+ COPY pyproject.toml poetry.lock /app
18
+ RUN poetry install
19
 
20
  EXPOSE 8501
21
 
poetry.lock ADDED
The diff for this file is too large to render. See raw diff
 
pyproject.toml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "sft"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = [
6
+ { name = "yongkyucho", email = "choco@conoz.net" },
7
+ ]
8
+ license = "MIT"
9
+ readme = "README.md"
10
+
11
+ [build-system]
12
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
13
+ build-backend = "poetry.core.masonry.api"
14
+
15
+ [tool.poetry.dependencies]
16
+ python = "~3.11"
17
+
18
+ torch = "2.7.0"
19
+ sentence-transformers = "^3.0.0"
20
+
21
+ streamlit = "^1.46.1"
22
+ # unsloth = "^2025.6.8"
requirements.txt CHANGED
@@ -1,3 +1,5 @@
1
  altair
2
  pandas
3
- streamlit
 
 
 
1
  altair
2
  pandas
3
+ streamlit
4
+ transformers
5
+ torch
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
+ import torch
3
+ from transformers import pipeline
4
+ # from unsloth import FastLanguageModel, is_bfloat16_supported
5
 
6
+
7
+ def main():
8
+ st.title('Text Generator')
9
+ query = st.text_input('input your topic of interest')
10
+
11
+ alpaca_template = """Below is an instruction that describes a task. Write a response that appropriately completes the request.
12
+
13
+ ### Instruction:
14
+ {}
15
+
16
+ ### Response:
17
+ {}
18
+ """
19
+
20
+ # model_id = "sentence-transformers/all-MiniLM-L6-v2"
21
+ # model_id = "sentence-transformers/xlm-r-base-en-ko-nli-ststb"
22
+
23
+ # model_id = "mistralai/Mistral-7B-Instruct-v0.1"
24
+ model_id = "meta-llama/Llama-3.2-1B"
25
+ # model_id="choco-conoz/TwinLlama-3.1-8B"
26
+ processor = pipeline(
27
+ "text-generation",
28
+ model=model_id,
29
+ model_kwargs={
30
+ "torch_dtype": torch.float16,
31
+ "quantization_config": {"load_in_4bit": True},
32
+ "low_cpu_mem_usage": True,
33
+ },
34
+ )
35
+ terminators = [
36
+ processor.tokenizer.eos_token_id,
37
+ processor.tokenizer.convert_tokens_to_ids(""),
38
+ ]
39
+
40
+ if st.button("Send"):
41
+ user_prompt = alpaca_template.format(query, "")
42
+ print('user_prompt', user_prompt)
43
+ prompt = processor.tokenizer.apply_chat_template(
44
+ user_prompt, tokenize=False, add_generation_prompt=True)
45
+ outputs = processor(prompt, max_new_tokens=4096, eos_token_id=terminators, do_sample=True,
46
+ temperature=0.6, top_p=0.9
47
+ )
48
+ response = outputs[0]["generated_text"][len(prompt):]
49
+ st.write(response)
50
+
51
+
52
+ if __name__ == "__main__":
53
+ main()
54
+ # >>> old
55
+ # num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
56
+ # num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
57
+
58
+ # indices = np.linspace(0, 1, num_points)
59
+ # theta = 2 * np.pi * num_turns * indices
60
+ # radius = indices
61
+
62
+ # x = radius * np.cos(theta)
63
+ # y = radius * np.sin(theta)
64
+
65
+ # df = pd.DataFrame({
66
+ # "x": x,
67
+ # "y": y,
68
+ # "idx": indices,
69
+ # "rand": np.random.randn(num_points),
70
+ # })
71
+
72
+ # st.altair_chart(alt.Chart(df, height=700, width=700)
73
+ # .mark_point(filled=True)
74
+ # .encode(
75
+ # x=alt.X("x", axis=None),
76
+ # y=alt.Y("y", axis=None),
77
+ # color=alt.Color("idx", legend=None, scale=alt.Scale()),
78
+ # size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
79
+ # ))