Spaces:
Runtime error
Runtime error
Initial commit
Browse files
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: 🐨
|
4 |
colorFrom: purple
|
5 |
colorTo: pink
|
|
|
1 |
---
|
2 |
+
title: BLOOM Spanish Prompts
|
3 |
emoji: 🐨
|
4 |
colorFrom: purple
|
5 |
colorTo: pink
|
app.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
from pathlib import Path
|
6 |
+
|
7 |
+
title = "BLOOM "
|
8 |
+
description = """Gradio Demo for using BLOOM with Spanish prompts.
|
9 |
+
Tips:
|
10 |
+
- Do NOT talk to BLOOM as an entity, it's not a chatbot but a webpage/blog/article completion model.
|
11 |
+
- For the best results: MIMIC a few sentences of a webpage similar to the content you want to generate.
|
12 |
+
Start a paragraph as if YOU were writing a blog, webpage, math post, coding article and BLOOM will generate a coherent follow-up. Longer prompts usually give more interesting results.
|
13 |
+
Options:
|
14 |
+
- sampling: imaginative completions (may be not super accurate e.g. math/history)
|
15 |
+
- greedy: accurate completions (may be more boring or have repetitions)
|
16 |
+
"""
|
17 |
+
|
18 |
+
API_URL = os.getenv("API_URL")
|
19 |
+
|
20 |
+
examples = [
|
21 |
+
['A "whatpu" is a small, furry animal native to Tanzania. An example of a sentence that uses the word whatpu is: We were traveling in Africa and we saw these very cute whatpus. To do a "farduddle" means to jump up and down really fast. An example of a sentence that uses the word farduddle is:', 32, "Sample", False, "Sample 1"],
|
22 |
+
['A poem about the beauty of science by Alfred Edgar Brittle\nTitle: The Magic Craft\nIn the old times', 50, "Sample", False, "Sample 1"],
|
23 |
+
['استخراج العدد العاملي في لغة بايثون:', 30, "Greedy", False, "Sample 1"],
|
24 |
+
["Pour déguster un ortolan, il faut tout d'abord", 32, "Sample", False, "Sample 1"],
|
25 |
+
['Traduce español de España a español de Argentina\nEl coche es rojo - el auto es rojo\nEl ordenador es nuevo - la computadora es nueva\nel boligrafo es negro -', 16, "Sample", False, "Sample 1"],
|
26 |
+
['Estos ejemplos quitan vocales de las palabras\nEjemplos:\nhola - hl\nmanzana - mnzn\npapas - pps\nalacran - lcrn\npapa -', 16, "Sample",False, "Sample 1"],
|
27 |
+
["Question: If I put cheese into the fridge, will it melt?\nAnswer:", 32, "Sample", False, "Sample 1"],
|
28 |
+
["Math exercise - answers:\n34+10=44\n54+20=", 16, "Greedy", False, "Sample 1"],
|
29 |
+
["Question: Where does the Greek Goddess Persephone spend half of the year when she is not with her mother?\nAnswer:", 24, "Greedy", False, "Sample 1"],
|
30 |
+
["spelling test answers.\nWhat are the letters in « language »?\nAnswer: l-a-n-g-u-a-g-e\nWhat are the letters in « Romanian »?\nAnswer:", 24, "Greedy", False, "Sample 1"],
|
31 |
+
]
|
32 |
+
|
33 |
+
def query(payload):
|
34 |
+
print(payload)
|
35 |
+
response = requests.request("POST", API_URL, json=payload)
|
36 |
+
print(response)
|
37 |
+
return json.loads(response.content.decode("utf-8"))
|
38 |
+
|
39 |
+
def inference(input_sentence, max_length, sample_or_greedy, seed=42):
|
40 |
+
if sample_or_greedy == "Sample":
|
41 |
+
parameters = {"max_new_tokens": max_length,
|
42 |
+
"top_p": 0.9,
|
43 |
+
"do_sample": True,
|
44 |
+
"seed": seed,
|
45 |
+
"early_stopping": False,
|
46 |
+
"length_penalty": 0.0,
|
47 |
+
"eos_token_id": None}
|
48 |
+
else:
|
49 |
+
parameters = {"max_new_tokens": max_length,
|
50 |
+
"do_sample": False,
|
51 |
+
"seed": seed,
|
52 |
+
"early_stopping": False,
|
53 |
+
"length_penalty": 0.0,
|
54 |
+
"eos_token_id": None}
|
55 |
+
|
56 |
+
payload = {"inputs": input_sentence,
|
57 |
+
"parameters": parameters}
|
58 |
+
|
59 |
+
data = query(
|
60 |
+
payload
|
61 |
+
)
|
62 |
+
|
63 |
+
|
64 |
+
return data[0]['generated_text']
|
65 |
+
|
66 |
+
|
67 |
+
gr.Interface(
|
68 |
+
inference,
|
69 |
+
[
|
70 |
+
gr.inputs.Textbox(label="Input"),
|
71 |
+
gr.inputs.Slider(1, 64, default=32, step=1, label="Tokens to generate"),
|
72 |
+
gr.inputs.Radio(["Sample", "Greedy"], label="Sample or greedy", default="Sample"),
|
73 |
+
gr.Checkbox(label="Just output raw text"),
|
74 |
+
gr.inputs.Radio(["Sample 1", "Sample 2", "Sample 3", "Sample 4", "Sample 5"], default="Sample 1", label="Sample other generations (only work in 'Sample' mode", type="index"),
|
75 |
+
],
|
76 |
+
["text"],
|
77 |
+
examples=examples,
|
78 |
+
# article=article,
|
79 |
+
cache_examples=False,
|
80 |
+
title=title,
|
81 |
+
description=description
|
82 |
+
).launch()
|