Spaces:
Configuration error

DigitSnap / app.py
Fngr-official's picture
Create app.py
71e2089 verified
Raw History Blame Contribute Delete
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("""
### ๊ธฐ๋ณธ ๊ธฐํ˜ธ
- `>` : ๋‹ค์Œ ์ž‘์—… ์—ฐ๊ฒฐ
- `-` : ๋‚ด์šฉ ์ œ์™ธ
- `@` : ๋งฅ๋ฝ ์ง€์ •
- `!` : ๊ฐ•์กฐ/ํ•„์ˆ˜
### ์‚ฌ์šฉ ์˜ˆ์‹œ
- `๋‰ด์Šค > ์š”์•ฝ -๊ด‘๊ณ `
- `์ˆ˜ํ•™ ์„ค๋ช… @์ค‘ํ•™์ƒ > ์˜ˆ์‹œ !`
- `์˜ค๋Š˜ ๋‰ด์Šค๋ฅผ ํ•œ ์ค„๋กœ ์š”์•ฝํ•ด์ค˜, ๊ด‘๊ณ ๋Š” ๋นผ๊ณ `
""")
# ๋ชจ๋ธ ๋กœ๋”ฉ ์บ์‹ฑ
@st.cache_resource
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% ํ† ํฐ ์ ˆ์•ฝ์œผ๋กœ ๋น ๋ฅธ ์‘๋‹ต
""")