Spaces:
Running
Running
Upload 6 files
Browse files- -adapter_config.json.url +2 -0
- -adapter_model.safetensors.url +2 -0
- README.md +207 -8
- app.py +95 -0
- gitattributes +35 -0
- requirements.txt +3 -0
-adapter_config.json.url
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
[InternetShortcut]
|
2 |
+
URL=https://drive.google.com/file/d/13kJyTU4P2hzl4kx4A6TGKT2Ks84oqdQL/view?usp=drive_web
|
-adapter_model.safetensors.url
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
[InternetShortcut]
|
2 |
+
URL=https://drive.google.com/file/d/1pwtJYMh4D61VXSFmsqCnwz5QOr3rAFUV/view?usp=drive_web
|
README.md
CHANGED
@@ -1,12 +1,211 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
-
app_file: app.py
|
9 |
pinned: false
|
|
|
|
|
|
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: StoryNest
|
3 |
+
emoji: π
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio # You can use "gradio" or "streamlit" based on your preference
|
7 |
+
sdk_version: "5.0.1" # Specify the version of Gradio or Streamlit
|
8 |
+
app_file: app.py # Specify the main Python file for your app
|
9 |
pinned: false
|
10 |
+
base_model: unsloth/qwen2.5-3b-unsloth-bnb-4bit
|
11 |
+
library_name: peft
|
12 |
+
|
13 |
---
|
14 |
|
15 |
+
# Model Card for Model ID
|
16 |
+
|
17 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
## Model Details
|
22 |
+
|
23 |
+
### Model Description
|
24 |
+
|
25 |
+
<!-- Provide a longer summary of what this model is. -->
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
- **Developed by:** [More Information Needed]
|
30 |
+
- **Funded by [optional]:** [More Information Needed]
|
31 |
+
- **Shared by [optional]:** [More Information Needed]
|
32 |
+
- **Model type:** [More Information Needed]
|
33 |
+
- **Language(s) (NLP):** [More Information Needed]
|
34 |
+
- **License:** [More Information Needed]
|
35 |
+
- **Finetuned from model [optional]:** [More Information Needed]
|
36 |
+
|
37 |
+
### Model Sources [optional]
|
38 |
+
|
39 |
+
<!-- Provide the basic links for the model. -->
|
40 |
+
|
41 |
+
- **Repository:** [More Information Needed]
|
42 |
+
- **Paper [optional]:** [More Information Needed]
|
43 |
+
- **Demo [optional]:** [More Information Needed]
|
44 |
+
|
45 |
+
## Uses
|
46 |
+
|
47 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
48 |
+
|
49 |
+
### Direct Use
|
50 |
+
|
51 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
52 |
+
|
53 |
+
[More Information Needed]
|
54 |
+
|
55 |
+
### Downstream Use [optional]
|
56 |
+
|
57 |
+
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
58 |
+
|
59 |
+
[More Information Needed]
|
60 |
+
|
61 |
+
### Out-of-Scope Use
|
62 |
+
|
63 |
+
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
64 |
+
|
65 |
+
[More Information Needed]
|
66 |
+
|
67 |
+
## Bias, Risks, and Limitations
|
68 |
+
|
69 |
+
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
70 |
+
|
71 |
+
[More Information Needed]
|
72 |
+
|
73 |
+
### Recommendations
|
74 |
+
|
75 |
+
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
76 |
+
|
77 |
+
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
78 |
+
|
79 |
+
## How to Get Started with the Model
|
80 |
+
|
81 |
+
Use the code below to get started with the model.
|
82 |
+
|
83 |
+
[More Information Needed]
|
84 |
+
|
85 |
+
## Training Details
|
86 |
+
|
87 |
+
### Training Data
|
88 |
+
|
89 |
+
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
90 |
+
|
91 |
+
[More Information Needed]
|
92 |
+
|
93 |
+
### Training Procedure
|
94 |
+
|
95 |
+
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
96 |
+
|
97 |
+
#### Preprocessing [optional]
|
98 |
+
|
99 |
+
[More Information Needed]
|
100 |
+
|
101 |
+
|
102 |
+
#### Training Hyperparameters
|
103 |
+
|
104 |
+
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
105 |
+
|
106 |
+
#### Speeds, Sizes, Times [optional]
|
107 |
+
|
108 |
+
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
109 |
+
|
110 |
+
[More Information Needed]
|
111 |
+
|
112 |
+
## Evaluation
|
113 |
+
|
114 |
+
<!-- This section describes the evaluation protocols and provides the results. -->
|
115 |
+
|
116 |
+
### Testing Data, Factors & Metrics
|
117 |
+
|
118 |
+
#### Testing Data
|
119 |
+
|
120 |
+
<!-- This should link to a Dataset Card if possible. -->
|
121 |
+
|
122 |
+
[More Information Needed]
|
123 |
+
|
124 |
+
#### Factors
|
125 |
+
|
126 |
+
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
127 |
+
|
128 |
+
[More Information Needed]
|
129 |
+
|
130 |
+
#### Metrics
|
131 |
+
|
132 |
+
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
133 |
+
|
134 |
+
[More Information Needed]
|
135 |
+
|
136 |
+
### Results
|
137 |
+
|
138 |
+
[More Information Needed]
|
139 |
+
|
140 |
+
#### Summary
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
## Model Examination [optional]
|
145 |
+
|
146 |
+
<!-- Relevant interpretability work for the model goes here -->
|
147 |
+
|
148 |
+
[More Information Needed]
|
149 |
+
|
150 |
+
## Environmental Impact
|
151 |
+
|
152 |
+
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
153 |
+
|
154 |
+
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
155 |
+
|
156 |
+
- **Hardware Type:** [More Information Needed]
|
157 |
+
- **Hours used:** [More Information Needed]
|
158 |
+
- **Cloud Provider:** [More Information Needed]
|
159 |
+
- **Compute Region:** [More Information Needed]
|
160 |
+
- **Carbon Emitted:** [More Information Needed]
|
161 |
+
|
162 |
+
## Technical Specifications [optional]
|
163 |
+
|
164 |
+
### Model Architecture and Objective
|
165 |
+
|
166 |
+
[More Information Needed]
|
167 |
+
|
168 |
+
### Compute Infrastructure
|
169 |
+
|
170 |
+
[More Information Needed]
|
171 |
+
|
172 |
+
#### Hardware
|
173 |
+
|
174 |
+
[More Information Needed]
|
175 |
+
|
176 |
+
#### Software
|
177 |
+
|
178 |
+
[More Information Needed]
|
179 |
+
|
180 |
+
## Citation [optional]
|
181 |
+
|
182 |
+
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
183 |
+
|
184 |
+
**BibTeX:**
|
185 |
+
|
186 |
+
[More Information Needed]
|
187 |
+
|
188 |
+
**APA:**
|
189 |
+
|
190 |
+
[More Information Needed]
|
191 |
+
|
192 |
+
## Glossary [optional]
|
193 |
+
|
194 |
+
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
195 |
+
|
196 |
+
[More Information Needed]
|
197 |
+
|
198 |
+
## More Information [optional]
|
199 |
+
|
200 |
+
[More Information Needed]
|
201 |
+
|
202 |
+
## Model Card Authors [optional]
|
203 |
+
|
204 |
+
[More Information Needed]
|
205 |
+
|
206 |
+
## Model Card Contact
|
207 |
+
|
208 |
+
[More Information Needed]
|
209 |
+
### Framework versions
|
210 |
+
|
211 |
+
- PEFT 0.14.0
|
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import socket
|
4 |
+
import warnings
|
5 |
+
from urllib3.exceptions import InsecureRequestWarning
|
6 |
+
import requests
|
7 |
+
from huggingface_hub import InferenceClient
|
8 |
+
|
9 |
+
# ββ 0) Monkeyβpatch DNS for the HF Inference API hostname ββββββββββββββββββββ
|
10 |
+
IP_POOL = [
|
11 |
+
"3.165.206.104",
|
12 |
+
"3.165.206.54",
|
13 |
+
"3.165.206.39",
|
14 |
+
"3.165.206.82",
|
15 |
+
]
|
16 |
+
_orig_getaddrinfo = socket.getaddrinfo
|
17 |
+
def patched_getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0):
|
18 |
+
if host == "api-inference.huggingface.co":
|
19 |
+
return [
|
20 |
+
(family or socket.AF_INET,
|
21 |
+
socktype or socket.SOCK_STREAM,
|
22 |
+
proto or socket.IPPROTO_TCP,
|
23 |
+
"",
|
24 |
+
(ip, port))
|
25 |
+
for ip in IP_POOL
|
26 |
+
]
|
27 |
+
return _orig_getaddrinfo(host, port, family, socktype, proto, flags)
|
28 |
+
socket.getaddrinfo = patched_getaddrinfo
|
29 |
+
|
30 |
+
# ββ 1) Sanityβcheck DNS + HTTP for example.com βββββββββββββββββββββββββββββββββ
|
31 |
+
try:
|
32 |
+
ip = socket.gethostbyname("example.com")
|
33 |
+
print("β
example.com β", ip)
|
34 |
+
except Exception as e:
|
35 |
+
print("β example.com DNS failed:", e)
|
36 |
+
try:
|
37 |
+
r = requests.get("https://example.com", timeout=5)
|
38 |
+
print("β
example.com GET β", r.status_code)
|
39 |
+
except Exception as e:
|
40 |
+
print("β example.com HTTP failed:", e)
|
41 |
+
|
42 |
+
# ββ 2) Load your HF token from Secrets and initialize the client βββββββββββββββ
|
43 |
+
HF_TOKEN = os.environ["HF_TOKEN"]
|
44 |
+
print("π HF_TOKEN present?", bool(HF_TOKEN))
|
45 |
+
|
46 |
+
# ββ CORRECTED: pass the model as positional or with the 'model=' keyword βββββ
|
47 |
+
client = InferenceClient(
|
48 |
+
model="HuggingFaceH4/zephyr-7b-beta", # β use 'model', not 'repo_id'
|
49 |
+
token=HF_TOKEN # β or api_key=HF_TOKEN
|
50 |
+
)
|
51 |
+
|
52 |
+
# ββ 3) Oneβshot chat function βββββββββββββββββββββββββββββββββββββββββββββββββ
|
53 |
+
def respond(
|
54 |
+
system_message: str,
|
55 |
+
user_prompt: str,
|
56 |
+
max_tokens: int,
|
57 |
+
temperature: float,
|
58 |
+
top_p: float
|
59 |
+
) -> str:
|
60 |
+
messages = [
|
61 |
+
{"role": "system", "content": system_message},
|
62 |
+
{"role": "user", "content": user_prompt}
|
63 |
+
]
|
64 |
+
resp = client.chat_completion(
|
65 |
+
messages,
|
66 |
+
max_tokens=max_tokens,
|
67 |
+
temperature=temperature,
|
68 |
+
top_p=top_p,
|
69 |
+
stream=False
|
70 |
+
)
|
71 |
+
chat_response = resp.choices[0].message.content.strip()
|
72 |
+
|
73 |
+
# Format the response to make it appear more like a chat
|
74 |
+
formatted_response = f"Assistant: {chat_response}"
|
75 |
+
return formatted_response
|
76 |
+
|
77 |
+
# ββ 4) Gradio Interface ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
78 |
+
demo = gr.Interface(
|
79 |
+
fn=respond,
|
80 |
+
inputs=[
|
81 |
+
gr.Textbox("You are a helpful and friendly assistant for children. Your capabilities include answering questions about children's books, characters, and events, and generating engaging, imaginative stories. It is essential that all your responses and generated stories are safe, appropriate, and positive for children. If a question or request is inappropriate, or if it is not about children's books or generating a safe story, please politely explain that you can only help with safe requests related to children's books or stories.", label="System message"),
|
82 |
+
gr.Textbox(placeholder="Type your questionβ¦", label="User prompt"),
|
83 |
+
gr.Slider(1, 2048, 512, label="Max tokens"),
|
84 |
+
gr.Slider(0.1, 4.0, 0.7, label="Temperature"),
|
85 |
+
gr.Slider(0.1, 1.0, 0.95, label="Top-p"),
|
86 |
+
],
|
87 |
+
outputs=gr.Textbox(label="Assistant reply"),
|
88 |
+
title="StoryNest Chat (OneβShot)",
|
89 |
+
flagging_mode="never",
|
90 |
+
)
|
91 |
+
|
92 |
+
# ββ 5) Launch with public API enabled ββββββββββββββββββββββββββββββββββββββββββ
|
93 |
+
demo.queue(api_open=True)
|
94 |
+
if __name__ == "__main__":
|
95 |
+
demo.launch()
|
gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio>=3.0
|
2 |
+
huggingface_hub==0.25.2
|
3 |
+
requests-toolbelt
|