Download app.py from Fngr/DigitSnap: direct link, hf CLI and curl.
- Browser
- Download file 4.11 kB
-
https://huggingface.co/spaces/Fngr/DigitSnap/resolve/main/app.py
- Command line
-
hf download hf://spaces/Fngr/DigitSnap/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Fngr/DigitSnap/resolve/main/app.py
4.11 kB
| import streamlit as st | |
| import torch | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| from snap_parse import snap_parse | |
| import time | |
| # ํ์ด์ง ์ค์ | |
| st.set_page_config( | |
| page_title="DigitSnap", | |
| page_icon="โก", | |
| layout="wide" | |
| ) | |
| # ํ์ดํ ๋ฐ ์๊ฐ | |
| st.title("โก DigitSnap") | |
| st.markdown("**SNAPโข + DeepSeek R1** - AI์์ ํจ์จ์ ์ธ ์ํธ์์ฉ์ ์ํ ๊ตฌ์กฐํ๋ ๋ช ๋ น์ด ์์คํ ") | |
| # ์ฌ์ด๋๋ฐ - SNAP ๊ฐ์ด๋ | |
| with st.sidebar: | |
| st.header("๐ SNAPโข ์ฌ์ฉ๋ฒ") | |
| st.markdown(""" | |
| ### ๊ธฐ๋ณธ ๊ธฐํธ | |
| - `>` : ๋ค์ ์์ ์ฐ๊ฒฐ | |
| - `-` : ๋ด์ฉ ์ ์ธ | |
| - `@` : ๋งฅ๋ฝ ์ง์ | |
| - `!` : ๊ฐ์กฐ/ํ์ | |
| ### ์ฌ์ฉ ์์ | |
| - `๋ด์ค > ์์ฝ -๊ด๊ณ ` | |
| - `์ํ ์ค๋ช @์คํ์ > ์์ !` | |
| - `์ค๋ ๋ด์ค๋ฅผ ํ ์ค๋ก ์์ฝํด์ค, ๊ด๊ณ ๋ ๋นผ๊ณ ` | |
| """) | |
| # ๋ชจ๋ธ ๋ก๋ฉ ์บ์ฑ | |
| def load_model(): | |
| try: | |
| tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-r1:1.5b") | |
| model = AutoModelForCausalLM.from_pretrained( | |
| "deepseek-ai/deepseek-r1:1.5b", | |
| torch_dtype=torch.float16, | |
| device_map="auto" | |
| ) | |
| return tokenizer, model | |
| except Exception as e: | |
| st.error(f"๋ชจ๋ธ ๋ก๋ฉ ์คํจ: {e}") | |
| return None, None | |
| # ๋ฉ์ธ ์ธํฐํ์ด์ค | |
| col1, col2 = st.columns([2, 1]) | |
| with col1: | |
| st.header("๐ฌ ๋ช ๋ น์ด ์ ๋ ฅ") | |
| user_input = st.text_area( | |
| "SNAP ๋ช ๋ น์ด ๋๋ ์์ฐ์ด๋ฅผ ์ ๋ ฅํ์ธ์:", | |
| placeholder="์: ์ค๋ ๋ด์ค๋ฅผ ํ ์ค๋ก ์์ฝํด์ค, ๊ด๊ณ ๋ ๋นผ๊ณ ", | |
| height=150 | |
| ) | |
| if st.button("๐ ์คํ", type="primary"): | |
| if user_input.strip(): | |
| # SNAP ํ์ฑ | |
| snap_command = snap_parse(user_input) | |
| # ํ์ฑ ๊ฒฐ๊ณผ ํ์ | |
| with col2: | |
| st.header("๐ง SNAP ํ์ฑ ๊ฒฐ๊ณผ") | |
| st.code(snap_command, language="text") | |
| # ๋ชจ๋ธ ์คํ | |
| with st.spinner("DeepSeek R1์ด ์๋ต์ ์์ฑํ๊ณ ์์ต๋๋ค..."): | |
| tokenizer, model = load_model() | |
| if tokenizer and model: | |
| try: | |
| # ํ ํฐํ ๋ฐ ์์ฑ | |
| inputs = tokenizer(snap_command, return_tensors="pt") | |
| with torch.no_grad(): | |
| outputs = model.generate( | |
| **inputs, | |
| max_new_tokens=256, | |
| temperature=0.7, | |
| do_sample=True, | |
| pad_token_id=tokenizer.eos_token_id | |
| ) | |
| # ๊ฒฐ๊ณผ ๋์ฝ๋ฉ | |
| result = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| # ์ ๋ ฅ ๋ถ๋ถ ์ ๊ฑฐ | |
| if snap_command in result: | |
| result = result.replace(snap_command, "").strip() | |
| st.header("๐ค DeepSeek R1 ์๋ต") | |
| st.markdown(result) | |
| except Exception as e: | |
| st.error(f"์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {e}") | |
| else: | |
| st.error("๋ชจ๋ธ์ ๋ก๋ฉํ ์ ์์ต๋๋ค.") | |
| else: | |
| st.warning("๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํด์ฃผ์ธ์.") | |
| with col2: | |
| if not user_input.strip(): | |
| st.header("๐ง SNAP ํ์ฑ ๊ฒฐ๊ณผ") | |
| st.info("๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ๋ฉด ํ์ฑ ๊ฒฐ๊ณผ๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค.") | |
| # ํ๋จ ์ ๋ณด | |
| st.markdown("---") | |
| st.markdown(""" | |
| ### ๐ DigitSnap ์ ๋ณด | |
| - **SNAPโข**: Simple Natural AI Protocol - AI ์ํธ์์ฉ์ ์ํ ๊ตฌ์กฐํ๋ ๋ช ๋ น์ด ์ธ์ด | |
| - **DeepSeek R1**: ๊ณ ์ฑ๋ฅ ์คํ์์ค ์ธ์ด๋ชจ๋ธ | |
| - **๋ถ๋ถ ์์ฐ์ด ์ง์**: ์์ฐ์ด์ SNAP ๊ธฐํธ๋ฅผ ์์ ๋กญ๊ฒ ํผ์ฉ ๊ฐ๋ฅ | |
| - **ํ ํฐ ํจ์จ์ฑ**: ์ต๋ 70% ํ ํฐ ์ ์ฝ์ผ๋ก ๋น ๋ฅธ ์๋ต | |
| """) | |