TheHickman commited on
Commit
c3881e4
·
verified ·
1 Parent(s): bc467fb

Update app.py

Browse files

GPT versions of all sites

Files changed (1) hide show
  1. app.py +262 -128
app.py CHANGED
@@ -81,131 +81,164 @@ TEXT_GENERATION = f"""
81
  <div id="hf-content" style="max-width: 800px; margin: auto; font-size: 16px; line-height: 1.6;">
82
  <h1>Text Generation (Hugging Face)</h1>
83
  <p>
84
- Generating text is the task of generating new text given another text.
85
- These models can, for example, fill in incomplete text or paraphrase.
86
  </p>
87
- {IMAGE_HTML}
88
  <h1>About Text Generation</h1>
89
  <p>
90
- This task covers guides on both <a href="https://huggingface.co/models?pipeline_tag=text-generation&sort=downloads">text-generation</a> and <a href="https://huggingface.co/models?other=text2text-generation&sort=downloads">text-to-text generation</a> models.
91
- Popular large language models that are used for chats or following instructions are also covered in this task.
92
- You can find the list of selected open-source large language models <a href="https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard">here</a>, ranked by their performance scores.
 
 
 
93
  </p>
94
 
95
  <h2>Use Cases</h2>
96
 
97
  <h3>Instruction Models</h3>
98
  <p>
99
- A model trained for text generation can be later adapted to follow instructions.
100
- You can try some of the most powerful instruction-tuned open-access models like Mixtral 8x7B, Cohere Command R+, and Meta Llama3 70B at <a href="https://huggingface.co/chat">Hugging Chat</a>.
 
101
  </p>
102
 
103
  <h3>Code Generation</h3>
104
  <p>
105
- A Text Generation model, also known as a causal language model, can be trained on code from scratch to help the programmers in their repetitive coding tasks.
106
- One of the most popular open-source models for code generation is StarCoder, which can generate code in 80+ languages. You can try it <a href="https://huggingface.co/spaces/bigcode/bigcode-playground">here</a>.
 
107
  </p>
108
 
109
- <h3>Stories Generation</h3>
110
  <p>
111
- A story generation model can receive an input like "Once upon a time" and proceed to create a story-like text based on those first words.
112
- You can try <a href="https://huggingface.co/spaces/mosaicml/mpt-7b-storywriter">this application</a> which contains a model trained on story generation, by MosaicML.
113
-
114
- If your generative model training data is different than your use case, you can train a causal language model from scratch.
115
- Learn how to do it in the free transformers <a href="https://huggingface.co/course/chapter7/6?fw=pt">course</a>!
116
  </p>
117
 
118
  <h2>Task Variants</h2>
119
 
120
- <h3>Completion Generation Models</h3>
121
  <p>
122
- A popular variant of Text Generation models predicts the next word given a bunch of words.
123
- Word by word a longer text is formed that results in for example:
124
  <ul>
125
- <li>Given an incomplete sentence, complete it.
126
- <li>Continue a story given the first sentences.
127
- <li>Provided a code description, generate the code.
128
  </ul>
129
- The most popular models for this task are GPT-based models, Mistral or Llama series.
130
- These models are trained on data that has no labels, so you just need plain text to train your own model.
131
- You can train text generation models to generate a wide variety of documents, from code to stories.
132
  </p>
133
 
134
- <h3>Text-to-Text Generation Models</h3>
135
  <p>
136
- These models are trained to learn the mapping between a pair of texts (e.g. translation from one language to another).
137
- The most popular variants of these models are NLLB, FLAN-T5, and BART.
138
- Text-to-Text models are trained with multi-tasking capabilities, they can accomplish a wide range of tasks, including summarization, translation, and text classification.
139
  </p>
140
- <h3>Language Model Variants</h3>
141
- When it comes to text generation, the underlying language model can come in several types:
142
- <ul>
143
- <li><b>Base models</b>: refers to plain language models like Mistral 7B and Meta Llama-3-70b. These models are good for fine-tuning and few-shot prompting.
144
- <li><b>Instruction-trained models</b>: these models are trained in a multi-task manner to follow a broad range of instructions like "Write me a recipe for chocolate cake". Models like Qwen 2 7B, Yi 1.5 34B Chat, and Meta Llama 70B Instruct are examples of instruction-trained models. In general, instruction-trained models will produce better responses to instructions than base models.
145
- <li><b>Human feedback models</b>: these models extend base and instruction-trained models by incorporating human feedback that rates the quality of the generated text according to criteria like helpfulness, honesty, and harmlessness. The human feedback is then combined with an optimization technique like reinforcement learning to align the original model to be closer with human preferences. The overall methodology is often called Reinforcement Learning from Human Feedback, or RLHF for short. Zephyr ORPO 141B A35B is an open-source model aligned through human feedback.
146
- </ul>
 
 
147
  <h2>Text Generation from Image and Text</h2>
148
  <p>
149
- There are language models that can input both text and image and output text, called vision language models.
150
- IDEFICS 2 and MiniCPM Llama3 V are good examples.
151
- They accept the same generation parameters as other language models.
152
- However, since they also take images as input, you have to use them with the image-to-text pipeline.
153
- You can find more information about this in the image-to-text task page.
154
  </p>
155
 
156
  <h2>Inference</h2>
157
  <p>
158
- You can use the 🤗 Transformers library <code>text-generation</code> pipeline to do inference
159
- with text generation models. It takes an input text and generates a continuation of that text.
160
  </p>
161
 
162
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
163
  from transformers import pipeline
164
- generator = pipeline('text-generation', model='gpt2')
165
  generator("Hello, I'm a language model,", max_length=30, num_return_sequences=3)
166
  </pre>
167
-
168
  <p>
169
- Text-to-Text generation models have a separate pipeline called text2text-generation.
170
- This pipeline takes an input containing the sentence including the task and returns the output of the accomplished task.
171
- <p>
172
- """ + """<pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
173
  from transformers import pipeline
174
-
175
  text2text_generator = pipeline("text2text-generation")
176
- text2text_generator("question: What is 42 ? context: 42 is the answer to life, the universe and everything")
177
- [{'generated_text': 'the answer to life, the universe and everything'}]
178
 
179
- text2text_generator("translate from English to French: I'm very happy")
180
- [{'generated_text': 'Je suis très heureux'}]
181
- </pre>
182
 
 
 
 
183
  <p>
184
- You can use huggingface.js to infer text classification models on Hugging Face Hub.
185
  </p>
186
 
187
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
188
  import { InferenceClient } from "@huggingface/inference";
189
 
190
  const inference = new InferenceClient(HF_TOKEN);
191
- await inference.conversational({
192
- model: "distilbert-base-uncased-finetuned-sst-2-english",
193
- inputs: "I love this movie!",
 
 
194
  });
 
 
195
  </pre>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
  <h2>Text Generation Inference</h2>
198
- <p>
199
- Text Generation Inference (TGI) is an open-source toolkit for serving LLMs tackling challenges such as response time.
200
- TGI powers inference solutions like Inference Endpoints and Hugging Chat, as well as multiple community projects.
201
- You can use it to deploy any supported open-source large language model of your choice.
202
- </p>
 
203
  <h2>ChatUI Spaces</h2>
204
- <p>
205
- Hugging Face Spaces includes templates to easily deploy your own instance of a specific application.
206
- ChatUI is an open-source interface that enables serving conversational interface for large language models and can be deployed with few clicks at Spaces.
207
- TGI powers these Spaces under the hood for faster inference.
208
- Thanks to the template, you can deploy your own instance based on a large language model with only a few clicks and customize it. Learn more about it here and create your large language model instance here.
 
209
  </div>
210
  """
211
 
@@ -213,47 +246,74 @@ QUESTION_ANSWER = f"""
213
  <div id="hf-content" style="max-width: 800px; margin: auto; font-size: 16px; line-height: 1.6;">
214
  <h1>Question Answering (Hugging Face)</h1>
215
  <p>
216
- Question Answering models can retrieve the answer to a question from a given text, which is useful for searching for an answer in a document.
217
- Some question answering models can generate answers without context!
 
218
  </p>
219
- {QA_IMAGE_HTML}
220
  <h1>About Question Answering</h1>
 
221
  <h2>Use Cases</h2>
222
  <h3>Frequently Asked Questions</h3>
223
  <p>
224
- You can use Question Answering (QA) models to automate the response to frequently asked questions by using a knowledge base (documents) as context.
225
- Answers to customer questions can be drawn from those documents.
226
- ⚡⚡ If you’d like to save inference time, you can first use <a href="https://huggingface.co/tasks/sentence-similarity">passage ranking</a> models to see which document might contain the answer to the question and iterate over that document with the QA model instead.
 
227
  </p>
 
228
  <h2>Task Variants</h2>
229
  <p>
230
- There are different QA variants based on the inputs and outputs:
231
  <ul>
232
- <li><b>Extractive QA:</b> The model <b>extracts</b> the answer from a context.
233
- The context here could be a provided text, a table or even HTML! This is usually solved with BERT-like models.</li>
234
- <li><b>Open Generative QA:</b> The model <b>generates</b> free text directly based on the context.
235
- You can learn more about the Text Generation task in its page.</li>
236
- <li><b>Closed Generative QA:</b> In this case, no context is provided. The answer is completely generated by a model.</li>
237
  </ul>
238
- The schema above illustrates extractive, open book QA. The model takes a context and the question and extracts the answer from the given context.
239
-
240
- You can also differentiate QA models depending on whether they are open-domain or closed-domain.
241
- Open-domain models are not restricted to a specific domain, while closed-domain models are restricted to a specific domain (e.g. legal, medical documents).
242
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  <h2>Inference</h2>
244
  <p>
245
- You can infer with QA models with the 🤗 Transformers library using the question-answering pipeline.
246
- If no model checkpoint is given, the pipeline will be initialized with distilbert-base-cased-distilled-squad.
247
- This pipeline takes a question and a context from which the answer will be extracted and returned.
248
  </p>
249
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
250
  from transformers import pipeline
251
 
252
  qa_model = pipeline("question-answering")
 
253
  question = "Where do I live?"
254
  context = "My name is Merve and I live in İstanbul."
255
- qa_model(question = question, context = context)
256
- ## {{'answer': 'İstanbul', 'end': 39, 'score': 0.953, 'start': 31}}
 
 
257
  </pre>
258
  </div>
259
  """
@@ -262,118 +322,192 @@ SUMMARISATION = f"""
262
  <div id="hf-content" style="max-width: 800px; margin: auto; font-size: 16px; line-height: 1.6;">
263
  <h1>Summarisation (Hugging Face)</h1>
264
  <p>
265
- Summarization is the task of producing a shorter version of a document while preserving its important information.
266
- Some models can extract text from the original input, while other models can generate entirely new text.
 
267
  </p>
268
- {SUMMARISATION_IMAGGE_HTML}
269
  <h1>About Summarisation</h1>
 
270
  <h2>Use Cases</h2>
271
- <h3>Research Paper Summarization 🧐</h3>
272
  <p>
273
- Research papers can be summarized to allow researchers to spend less time selecting which articles to read.
274
- There are several approaches you can take for a task like this:
275
  <ol>
276
- <li>Use an existing extractive summarization model on the Hub to do inference.</li>
277
- <li>Pick an existing language model trained for academic papers. This model can then be trained in a process called fine-tuning so it can solve the summarization task.</li>
278
- <li>Use a sequence-to-sequence model like T5 for abstractive text summarization.</li>
279
  </ol>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  <h3>Inference</h3>
282
  <p>
283
- You can use the 🤗 Transformers library summarization pipeline to infer with existing Summarization models.
284
- If no model name is provided the pipeline will be initialized with <a href="https://huggingface.co/sshleifer/distilbart-cnn-12-6">sshleifer/distilbart-cnn-12-6</a>.
285
  </p>
286
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
287
  from transformers import pipeline
288
 
289
- classifier = pipeline("summarization")
290
- classifier("Paris is the capital and most populous city of France, with an estimated population of 2,175,601 residents as of 2018, in an area of more than 105 square kilometres (41 square miles). The City of Paris is the centre and seat of government of the region and province of Île-de-France, or Paris Region, which has an estimated population of 12,174,880, or about 18 percent of the population of France as of 2017.")
291
- ## [{{ "summary_text": " Paris is the capital and most populous city of France..." }}]
 
 
 
 
 
 
292
  </pre>
293
 
294
  <p>
295
- You can use <a href="https://github.com/huggingface/huggingface.js">huggingface.js</a> to infer summarization models on Hugging Face Hub.
296
  </p>
297
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
298
  import {{ InferenceClient }} from "@huggingface/inference";
299
 
300
  const inference = new InferenceClient(HF_TOKEN);
301
  const inputs =
302
- "Paris is the capital and most populous city of France, with an estimated population of 2,175,601 residents as of 2018, in an area of more than 105 square kilometres (41 square miles). The City of Paris is the centre and seat of government of the region and province of Île-de-France, or Paris Region, which has an estimated population of 12,174,880, or about 18 percent of the population of France as of 2017.";
 
 
 
303
 
304
  await inference.summarization({{
305
- model: "sshleifer/distilbart-cnn-12-6",
306
- inputs,
307
  }});
308
  </pre>
309
- </div>
310
  """
311
 
312
  TEXT_2_IMAGGE = f"""
313
  <div id="hf-content" style="max-width: 800px; margin: auto; font-size: 16px; line-height: 1.6;">
314
  <h1>Text-to-Image (Hugging Face)</h1>
315
  <p>
316
- Text-to-image is the task of generating images from input text. These pipelines can also be used to modify and edit images based on text prompts.
 
317
  </p>
318
  {TEXT2IMAGE_IMAGE_HTML}
319
  <h1>About Text-to-Image</h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  <h2>Use Cases</h2>
321
  <h3>Data Generation</h3>
322
  <p>
323
- Businesses can generate data for their use cases by inputting text and getting image outputs.
324
  </p>
325
  <h3>Immersive Conversational Chatbots</h3>
326
  <p>
327
- Chatbots can be made more immersive if they provide contextual images based on the input provided by the user.
328
  </p>
329
  <h3>Creative Ideas for Fashion Industry</h3>
330
  <p>
331
- Different patterns can be generated to obtain unique pieces of fashion.
332
- Text-to-image models make creations easier for designers to conceptualize their design before actually implementing it.
333
  </p>
334
  <h3>Architecture Industry </h3>
335
  <p>
336
- Architects can utilise the models to construct an environment based out on the requirements of the floor plan.
337
- This can also include the furniture that has to be placed in that environment.
338
  </p>
 
339
  <h2>Task Variants</h2>
340
  <h3>Image Editing</h3>
341
  <p>
342
- Image editing with text-to-image models involves modifying an image following edit instructions provided in a text prompt.
343
  <ul>
344
- <li><b>Synthetic image editing:</b> Adjusting images that were initially created using an input prompt while preserving the overall meaning or context of the original image.</li>
345
  </ul>
346
  {SYNTHETIC_HTML}
347
  <ul>
348
- <li>Real image editing: Similar to synthetic image editing, except we're using real photos/images. This task is usually more complex.</li>
349
  </ul>
350
  {REAL_HTML}
351
- </p>
 
352
  <h3>Personalization</h3>
353
  <p>
354
- Personalization refers to techniques used to customize text-to-image models.
355
- We introduce new subjects or concepts to the model, which the model can then generate when we refer to them with a text prompt.
356
-
357
- For example, you can use these techniques to generate images of your dog in imaginary settings, after you have taught the model using a few reference images of the subject (or just one in some cases).
358
- Teaching the model a new concept can be achieved through fine-tuning, or by using training-free techniques.
359
  </p>
 
 
 
 
 
 
 
 
 
 
 
360
  <h3>Inference</h3>
361
  <p>
362
- You can use diffusers pipelines to infer with text-to-image models.
 
363
  </p>
364
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
365
  from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
 
366
 
367
  model_id = "stabilityai/stable-diffusion-2"
368
  scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
369
  pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16)
370
- pipe = pipe.to("cuda")
371
 
372
  prompt = "a photo of an astronaut riding a horse on mars"
373
  image = pipe(prompt).images[0]
374
  </pre>
375
  <p>
376
- You can use <a href="https://github.com/huggingface/huggingface.js">huggingface.js</a> to infer text-to-image models on Hugging Face Hub.
377
  </p>
378
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
379
  import {{ InferenceClient }} from "@huggingface/inference";
 
81
  <div id="hf-content" style="max-width: 800px; margin: auto; font-size: 16px; line-height: 1.6;">
82
  <h1>Text Generation (Hugging Face)</h1>
83
  <p>
84
+ Text generation is like supercharged autocomplete. You type a few words, and the model continues the text.
85
+ It can complete sentences, answer questions, rewrite text, or follow instructions like a helpful assistant.
86
  </p>
87
+ {IMAGE_HTML}""" + """
88
  <h1>About Text Generation</h1>
89
  <p>
90
+ This page covers two main types of models:
91
+ <a href="https://huggingface.co/models?pipeline_tag=text-generation&sort=downloads">text generation</a> (continue the text) and
92
+ <a href="https://huggingface.co/models?other=text2text-generation&sort=downloads">text-to-text generation</a> (turn one text into another, like translate or summarize).
93
+ Popular open models used for chat and instructions are also included.
94
+ You can see a ranked list of open large language models
95
+ <a href="https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard">here</a>.
96
  </p>
97
 
98
  <h2>Use Cases</h2>
99
 
100
  <h3>Instruction Models</h3>
101
  <p>
102
+ Some models are tuned to follow everyday instructions, such as “Write a friendly email to my landlord.
103
+ Try open-access models like Mixtral 8x7B, Cohere Command R+, and Meta Llama 3 70B in
104
+ <a href="https://huggingface.co/chat">Hugging Chat</a>.
105
  </p>
106
 
107
  <h3>Code Generation</h3>
108
  <p>
109
+ Models can also help with coding by writing snippets from descriptions or continuing your code.
110
+ StarCoder is a popular open model that can write code in many languages. Try it
111
+ <a href="https://huggingface.co/spaces/bigcode/bigcode-playground">here</a>.
112
  </p>
113
 
114
+ <h3>Story Writing</h3>
115
  <p>
116
+ Give a starting line like Once upon a time and the model can continue with a story.
117
+ Try a story-focused app by MosaicML
118
+ <a href="https://huggingface.co/spaces/mosaicml/mpt-7b-storywriter">here</a>.
119
+ If your needs are very specific, you can train a model from scratch. Learn how in the free Transformers
120
+ <a href="https://huggingface.co/course/chapter7/6?fw=pt">course</a>.
121
  </p>
122
 
123
  <h2>Task Variants</h2>
124
 
125
+ <h3>Completion-Style Models</h3>
126
  <p>
127
+ These models predict the next words, one after another, to build longer text. They can:
 
128
  <ul>
129
+ <li>Finish an incomplete sentence.</li>
130
+ <li>Continue a story from a few opening lines.</li>
131
+ <li>Write code from a short description.</li>
132
  </ul>
133
+ Popular families include GPT-style models, Mistral, and the Llama series.
134
+ They learn from lots of regular text, so they’re flexible: letters, stories, FAQs, notes, and more.
 
135
  </p>
136
 
137
+ <h3>Text-to-Text Models</h3>
138
  <p>
139
+ These models turn one piece of text into another. For example, they can summarize, translate, or answer questions in a fixed format.
140
+ Well-known examples include FLAN-T5 and BART.
141
+ You tell the model the task in the input (like “Summarize: …”), and it returns the result.
142
  </p>
143
+
144
+ <h3>Language Model Types</h3>
145
+ <p>When you pick a model, you’ll often see three broad types:</p>
146
+ <ul>
147
+ <li><b>Base models</b>: general-purpose models (for example, Mistral 7B or Meta Llama 3) that are good starting points. They’re great if you plan to customize or give examples in your prompt.</li>
148
+ <li><b>Instruction-tuned models</b>: trained to follow everyday requests like “Write a recipe for chocolate cake. These usually give more helpful replies out of the box (for example, Qwen 2 7B, Yi 1.5 34B Chat, Llama 3 Instruct).</li>
149
+ <li><b>Human feedback–aligned models</b>: further adjusted using people’s ratings so the answers are more helpful and safe. Open models like Zephyr are examples of this approach.</li>
150
+ </ul>
151
+
152
  <h2>Text Generation from Image and Text</h2>
153
  <p>
154
+ Some models can look at images and text together, then write text as the answer.
155
+ IDEFICS 2 and MiniCPM Llama 3 V are good examples.
156
+ They work like other text models but also accept images.
157
+ Use them with the image-to-text tools. You can learn more on the image-to-text task page.
 
158
  </p>
159
 
160
  <h2>Inference</h2>
161
  <p>
162
+ You can use the 🤗 Transformers <code>text-generation</code> helper to run a model.
163
+ Give it a starting prompt, and it will continue from there.
164
  </p>
165
 
166
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
167
  from transformers import pipeline
168
+ generator = pipeline("text-generation", model="gpt2")
169
  generator("Hello, I'm a language model,", max_length=30, num_return_sequences=3)
170
  </pre>
 
171
  <p>
172
+ Text-to-text models use a separate <code>text2text-generation</code> helper.
173
+ You include the task in the input, and the model returns the result.
174
+ </p>
175
+ <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
176
  from transformers import pipeline
 
177
  text2text_generator = pipeline("text2text-generation")
 
 
178
 
179
+ text2text_generator("question: What is 42? context: 42 is the answer to life, the universe and everything")
180
+ # [{'generated_text': 'the answer to life, the universe and everything'}]
 
181
 
182
+ text2text_generator("translate from English to French: I'm very happy")
183
+ # [{'generated_text': 'Je suis très heureux'}]
184
+ </pre>
185
  <p>
186
+ You can also use huggingface.js to run text generation models from the browser or Node.js.
187
  </p>
188
 
189
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
190
  import { InferenceClient } from "@huggingface/inference";
191
 
192
  const inference = new InferenceClient(HF_TOKEN);
193
+
194
+ const result = await inference.textGeneration({
195
+ model: "gpt2",
196
+ inputs: "Write a cheerful greeting about summer:",
197
+ parameters: { max_new_tokens: 50 }
198
  });
199
+
200
+ console.log(result.generated_text);
201
  </pre>
202
+
203
+ <h2>Getting Good Results</h2>
204
+ <p>
205
+ Think of these models as smart helpers that guess what should come next based on patterns they’ve seen.
206
+ To get strong, useful answers:
207
+ </p>
208
+ <ul>
209
+ <li><b>Be clear and specific</b>: say exactly what you want, include any rules (tone, length, format), and give examples if helpful.</li>
210
+ <li><b>Pick the right model size</b>: bigger models can be more capable, but smaller ones are faster and cheaper. Choose what fits your task.</li>
211
+ <li><b>Use the right kind</b>: instruction-tuned models usually follow requests better than base models.</li>
212
+ <li><b>Give enough context</b>: include key details the model needs (background info, style, audience).</li>
213
+ <li><b>Adjust generation settings</b>: temperature/top‑p control creativity; max tokens control length. Try small changes and compare results.</li>
214
+ <li><b>Domain data helps</b>: for very specific topics (legal, medical, in-house jargon), fine-tuning or giving examples can improve accuracy.</li>
215
+ <li><b>Review and iterate</b>: ask for revisions, or try a different prompt if the first try isn’t right.</li>
216
+ </ul>
217
+
218
+ <h2>Limits and Common Misconceptions</h2>
219
+ <ul>
220
+ <li><b>Not a database of facts</b>: models can sound confident yet be wrong. Always verify important information.</li>
221
+ <li><b>Can reflect biases</b>: outputs may mirror issues in the data they learned from. Add guidelines and checks for fairness and tone.</li>
222
+ <li><b>No personal memory by default</b>: they don’t remember past chats unless you include that text again or build a system to store it.</li>
223
+ <li><b>Privacy matters</b>: don’t share sensitive data unless you use secure, compliant setups.</li>
224
+ <li><b>Length limits</b>: models can only read a certain amount of text at once. Summarize or chunk long inputs.</li>
225
+ <li><b>Creativity vs. accuracy</b>: more creative settings may produce lively text but also more mistakes. Tune for your goal.</li>
226
+ </ul>
227
 
228
  <h2>Text Generation Inference</h2>
229
+ <p>
230
+ Text Generation Inference (TGI) is an open toolkit for serving large models with fast responses.
231
+ It powers services like Inference Endpoints and Hugging Chat, and many community projects.
232
+ You can use it to deploy supported open models of your choice.
233
+ </p>
234
+
235
  <h2>ChatUI Spaces</h2>
236
+ <p>
237
+ Hugging Face Spaces has templates to spin up your own chat app with just a few clicks.
238
+ ChatUI is an open interface for building a conversational experience around a large language model.
239
+ Under the hood, Spaces can use TGI for faster replies.
240
+ Start from a template, customize it, and launch your own model-backed chat in minutes.
241
+ </p>
242
  </div>
243
  """
244
 
 
246
  <div id="hf-content" style="max-width: 800px; margin: auto; font-size: 16px; line-height: 1.6;">
247
  <h1>Question Answering (Hugging Face)</h1>
248
  <p>
249
+ Question Answering (QA) is about asking a question and getting an answer from text you provide.
250
+ Think of it like using “find” in a digital book: you ask a question, and the tool scans the text to pull out the answer.
251
+ Some QA systems can also answer without any text given, by writing an answer on their own.
252
  </p>
253
+ {QA_IMAGE_HTML}"""+"""
254
  <h1>About Question Answering</h1>
255
+
256
  <h2>Use Cases</h2>
257
  <h3>Frequently Asked Questions</h3>
258
  <p>
259
+ QA models can help automatically answer common questions by looking up information in a set of documents (your knowledge base).
260
+ For example, a customer support bot can pull answers from product manuals or help center articles.
261
+ ⚡⚡ To speed things up, you can first find the most relevant page or paragraph, then run QA only on that smaller piece.
262
+ One way to do this is with <a href="https://huggingface.co/tasks/sentence-similarity">passage ranking</a> models that suggest where the answer is most likely to be.
263
  </p>
264
+
265
  <h2>Task Variants</h2>
266
  <p>
267
+ There are a few ways QA can work, depending on what you give it and what you want back:
268
  <ul>
269
+ <li><b>Extractive QA:</b> The model <b>picks</b> the answer from the text you provide (like highlighting a sentence in a document).
270
+ The text could be a paragraph, a table, or even a web page.</li>
271
+ <li><b>Open Generative QA:</b> You give some text as context, and the model <b>writes</b> the answer in its own words based on that text.</li>
272
+ <li><b>Closed Generative QA:</b> You do <b>not</b> give any text. The model writes an answer from what it has learned before. (This can be helpful, but it can also guess or be wrong.)</li>
 
273
  </ul>
274
+ The visual above shows the open-book style: you provide both a question and some text, and the model pulls the answer from that text.
275
+ <br><br>
276
+ Some models aim to handle any topic, while others are trained for a specific field (for example, law or medicine).
277
+ Topic‑specific models can do better on their area but may struggle outside it.
278
  </p>
279
+
280
+ <h2>What you need for good results</h2>
281
+ <ul>
282
+ <li><b>Clear questions:</b> Short, direct questions work best (“What is the refund period?”).</li>
283
+ <li><b>Relevant context:</b> Provide text that actually contains the answer. If the answer isn’t there, extractive QA cannot find it.</li>
284
+ <li><b>High‑quality sources:</b> Clean, up‑to‑date documents lead to better answers.</li>
285
+ <li><b>Right model for the job:</b> Use models that support your language and, if needed, your domain (e.g., legal, medical).</li>
286
+ <li><b>Manage long documents:</b> Break long text into smaller parts or first pick the most relevant passage before running QA.</li>
287
+ <li><b>Be specific:</b> If a question can mean many things, clarify it to reduce confusion.</li>
288
+ </ul>
289
+
290
+ <h2>Limits and common misconceptions</h2>
291
+ <ul>
292
+ <li><b>Extractive QA cannot invent answers:</b> If the text doesn’t contain the answer, it won’t magically appear.</li>
293
+ <li><b>Generative QA can make things up:</b> When writing answers, models may sound confident but be wrong. Verify important facts.</li>
294
+ <li><b>Not a web browser:</b> QA does not search the internet unless you connect it to a search or retrieval step.</li>
295
+ <li><b>Confidence is not certainty:</b> A high score does not guarantee correctness; always sanity‑check critical outputs.</li>
296
+ <li><b>Very long or messy input can confuse the model:</b> Short, relevant passages work better.</li>
297
+ <li><b>Sensitive topics need human review:</b> For medical, legal, or safety‑critical answers, involve an expert.</li>
298
+ </ul>
299
+
300
  <h2>Inference</h2>
301
  <p>
302
+ You can try QA with the 🤗 Transformers library using the questionanswering pipeline.
303
+ If you don’t choose a specific model, it uses a small default one (distilbert-base-cased-distilled-squad).
304
+ Give it a question and a piece of text that contains the answer, and it will return the answer span.
305
  </p>
306
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
307
  from transformers import pipeline
308
 
309
  qa_model = pipeline("question-answering")
310
+
311
  question = "Where do I live?"
312
  context = "My name is Merve and I live in İstanbul."
313
+
314
+ result = qa_model(question=question, context=context)
315
+ print(result)
316
+ # Example: {'answer': 'İstanbul', 'start': 31, 'end': 39, 'score': 0.953}
317
  </pre>
318
  </div>
319
  """
 
322
  <div id="hf-content" style="max-width: 800px; margin: auto; font-size: 16px; line-height: 1.6;">
323
  <h1>Summarisation (Hugging Face)</h1>
324
  <p>
325
+ Summarisation means turning a long piece of text into a much shorter version that keeps the main ideas.
326
+ Think of it like a movie trailer for an article: you get the key moments without watching the whole film.
327
+ Some tools pick the most important sentences from the original text, while others rewrite the main points in their own words.
328
  </p>
329
+ {SUMMARISATION_IMAGGE_HTML}""" + """
330
  <h1>About Summarisation</h1>
331
+
332
  <h2>Use Cases</h2>
333
+ <h3>Research Paper Summarisation 🧐</h3>
334
  <p>
335
+ Summaries of research papers help readers quickly decide what to read in full. You can approach this in a few simple ways:
 
336
  <ol>
337
+ <li>Use an existing summariser from the Hugging Face Hub and run it as-is.</li>
338
+ <li>Choose a model that works well on academic writing and, if needed, teach it with your own examples so it better matches your field.</li>
339
+ <li>Use a model that rewrites content in its own words (for example, T5) to create clear, natural summaries.</li>
340
  </ol>
341
+ Real-world examples:
342
+ - A scientist gets a short overview of a 20-page paper before diving in.
343
+ - A student creates a quick “abstract-style” note from lecture notes.
344
+ - A librarian builds short descriptions for new entries in a repository.
345
+ </p>
346
+
347
+ <h3>What helps good performance</h3>
348
+ <p>
349
+ To get clear and reliable summaries:
350
+ <ul>
351
+ <li>Start with clean input: remove boilerplate (menus, ads, repeated footers).</li>
352
+ <li>Match the model to your content type: news, scientific text, product reviews, etc.</li>
353
+ <li>Give enough context: include the full section you want summarised, not just a fragment.</li>
354
+ <li>Set the target length: decide if you want a headline, a paragraph, or a multi-paragraph summary.</li>
355
+ <li>Use examples when possible: if you can, show the model examples of “good” summaries for your use case.</li>
356
+ </ul>
357
+ Analogy: If you want a great travel summary, give the guide your full itinerary and tell them how long the recap should be.
358
  </p>
359
+
360
+ <h3>Limits and common misconceptions</h3>
361
+ <p>
362
+ It’s important to know what summarisation can and cannot do:
363
+ <ul>
364
+ <li>May miss fine details: short summaries can skip edge cases, citations, or numbers.</li>
365
+ <li>Can sound confident but be wrong: some models may introduce small mistakes or dates that weren’t in the text.</li>
366
+ <li>Very long documents are hard: splitting into sections and summarising step by step often works better.</li>
367
+ <li>Style matters: a model used to news articles may not do as well on legal or medical text without examples.</li>
368
+ <li>Not a replacement for careful reading: don’t rely on a summary alone for decisions with high stakes.</li>
369
+ </ul>
370
+ Common misconception: “The model truly understands the text.” In reality, it’s very good at pattern-matching and rewriting, but it doesn’t “know” like a human does.
371
+ </p>
372
+
373
  <h3>Inference</h3>
374
  <p>
375
+ You can use the 🤗 Transformers summarisation pipeline to run existing models.
376
+ If you don’t provide a model name, it uses <a href="https://huggingface.co/sshleifer/distilbart-cnn-12-6">sshleifer/distilbart-cnn-12-6</a> by default.
377
  </p>
378
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
379
  from transformers import pipeline
380
 
381
+ summarizer = pipeline("summarization")
382
+ result = summarizer(
383
+ "Paris is the capital and most populous city of France, with an estimated population of 2,175,601 residents as of 2018, "
384
+ "in an area of more than 105 square kilometres (41 square miles). The City of Paris is the centre and seat of government "
385
+ "of the region and province of Île-de-France, or Paris Region, which has an estimated population of 12,174,880, or about "
386
+ "18 percent of the population of France as of 2017."
387
+ )
388
+ print(result)
389
+ ## [{{ "summary_text": "Paris is the capital and most populous city of France..." }}]
390
  </pre>
391
 
392
  <p>
393
+ You can also use <a href="https://github.com/huggingface/huggingface.js">huggingface.js</a> to run summarisation models hosted on Hugging Face Hub.
394
  </p>
395
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
396
  import {{ InferenceClient }} from "@huggingface/inference";
397
 
398
  const inference = new InferenceClient(HF_TOKEN);
399
  const inputs =
400
+ "Paris is the capital and most populous city of France, with an estimated population of 2,175,601 residents as of 2018, "
401
+ + "in an area of more than 105 square kilometres (41 square miles). The City of Paris is the centre and seat of government of "
402
+ + "the region and province of Île-de-France, or Paris Region, which has an estimated population of 12,174,880, or about 18 percent "
403
+ + "of the population of France as of 2017.";
404
 
405
  await inference.summarization({{
406
+ model: "sshleifer/distilbart-cnn-12-6",
407
+ inputs,
408
  }});
409
  </pre>
410
+ </div>
411
  """
412
 
413
  TEXT_2_IMAGGE = f"""
414
  <div id="hf-content" style="max-width: 800px; margin: auto; font-size: 16px; line-height: 1.6;">
415
  <h1>Text-to-Image (Hugging Face)</h1>
416
  <p>
417
+ Text-to-image tools turn words into pictures. You describe what you want (like telling an artist), and the system creates an image from that description.
418
+ These tools can also change existing photos by following simple written instructions.
419
  </p>
420
  {TEXT2IMAGE_IMAGE_HTML}
421
  <h1>About Text-to-Image</h1>
422
+
423
+ <h2>What this can do</h2>
424
+ <p>
425
+ Think of it like giving directions to a skilled illustrator. You can ask for:
426
+ </p>
427
+ <ul>
428
+ <li>Brand-new images made from a short sentence or detailed paragraph.</li>
429
+ <li>Edits to your own photos (for example, “make the sky orange” or “add a cozy lamp on the table”).</li>
430
+ <li>Variations on a theme (try different styles, moods, or times of day).</li>
431
+ </ul>
432
+
433
+ <h2>What you need for good results</h2>
434
+ <ul>
435
+ <li>Clear instructions: Mention the main subject, setting, style, and any key details. Start simple, then add specifics.</li>
436
+ <li>Good input images (for editing): Sharp, well-lit photos make better edits.</li>
437
+ <li>Right model choice: Some models are better at people, products, or certain art styles.</li>
438
+ <li>Enough compute: A modern GPU speeds things up and can improve output size/quality.</li>
439
+ <li>Iterate: Try a basic prompt first, look at the result, then refine your wording step by step.</li>
440
+ </ul>
441
+
442
  <h2>Use Cases</h2>
443
  <h3>Data Generation</h3>
444
  <p>
445
+ Companies can quickly create example images from text to plan ideas, test layouts, or fill prototypes without needing a photo shoot.
446
  </p>
447
  <h3>Immersive Conversational Chatbots</h3>
448
  <p>
449
+ Chatbots can show helpful images on the fly (like “show me a cozy reading corner” or “illustrate this recipe’s final dish”) to make conversations more engaging.
450
  </p>
451
  <h3>Creative Ideas for Fashion Industry</h3>
452
  <p>
453
+ Designers can explore patterns, colors, and cuts before making real samples.
454
+ It’s like sketching hundreds of options instantly to see what stands out.
455
  </p>
456
  <h3>Architecture Industry </h3>
457
  <p>
458
+ Architects and interior designers can visualize rooms from rough descriptions (floor plans, style, furniture) to quickly explore different looks and layouts.
 
459
  </p>
460
+
461
  <h2>Task Variants</h2>
462
  <h3>Image Editing</h3>
463
  <p>
464
+ You can change an image by writing simple instructions (for example, “turn it into sunset lighting” or “add a plant next to the sofa”).
465
  <ul>
466
+ <li><b>Synthetic image editing:</b> Editing images that were created by a model in the first place, while keeping the main idea the same.</li>
467
  </ul>
468
  {SYNTHETIC_HTML}
469
  <ul>
470
+ <li>Real image editing: Editing real photos. This is often trickier because the model must match real-world lighting, texture, and detail.</li>
471
  </ul>
472
  {REAL_HTML}
473
+ </p>""" + """
474
+
475
  <h3>Personalization</h3>
476
  <p>
477
+ Personalization means teaching the system about a new subject (like your dog, your product, or your logo) using a few example photos.
478
+ After that, you can ask for new images of that same subject in different scenes (for example, “my dog as an astronaut”).
479
+ This can be done by briefly “learning” from your examples or by using lighter, training-free methods.
 
 
480
  </p>
481
+
482
+ <h2>Limits and common misconceptions</h2>
483
+ <ul>
484
+ <li>Realism varies: Hands, text in images (like signs), and fine details can look odd or inaccurate.</li>
485
+ <li>Consistency is hard: Getting the exact same character or object across many images can be difficult without personalization.</li>
486
+ <li>Bias and gaps: Outputs reflect patterns in the data the model learned from and may contain bias or miss niche subjects.</li>
487
+ <li>Not a search engine: It creates new images; it doesn’t pull exact photos from the internet.</li>
488
+ <li>Resolution trade-offs: Very high-resolution images may need more steps or upscaling tools.</li>
489
+ <li>Safety and rights: Avoid sharing sensitive images. Be mindful of copyrights, trademarks, and people’s privacy.</li>
490
+ </ul>
491
+
492
  <h3>Inference</h3>
493
  <p>
494
+ You can run text-to-image models locally with diffusers pipelines, or call them from the web.
495
+ Try a short, simple prompt first. If the result is close, add details in small steps.
496
  </p>
497
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
498
  from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
499
+ import torch
500
 
501
  model_id = "stabilityai/stable-diffusion-2"
502
  scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
503
  pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16)
504
+ pipe = pipe.to("cuda") # Use GPU if available for faster, higher-quality results
505
 
506
  prompt = "a photo of an astronaut riding a horse on mars"
507
  image = pipe(prompt).images[0]
508
  </pre>
509
  <p>
510
+ You can use <a href="https://github.com/huggingface/huggingface.js">huggingface.js</a> to run text-to-image models on Hugging Face Hub.
511
  </p>
512
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
513
  import {{ InferenceClient }} from "@huggingface/inference";