Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
+
import spacy
|
3 |
+
import torch
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
nlp = spacy.load('es_core_news_sm')
|
7 |
+
|
8 |
+
models = {
|
9 |
+
"stabilityai/stablelm-tuned-alpha-7b": AutoModelForCausalLM.from_pretrained("stabilityai/stablelm-tuned-alpha-7b"),
|
10 |
+
"CRD716/ggml-LLaMa-65B-quantized": AutoModelForCausalLM.from_pretrained("CRD716/ggml-LLaMa-65B-quantized"),
|
11 |
+
"RedXeol/bertin-gpt-j-6B-alpaca-4bit-128g": AutoModelForCausalLM.from_pretrained("RedXeol/bertin-gpt-j-6B-alpaca-4bit-128g"),
|
12 |
+
"bertin-project/bertin-alpaca-lora-7b": AutoModelForCausalLM.from_pretrained("bertin-project/bertin-alpaca-lora-7b")
|
13 |
+
}
|
14 |
+
|
15 |
+
tokenizers = {
|
16 |
+
"stabilityai/stablelm-tuned-alpha-7b": AutoTokenizer.from_pretrained("stabilityai/stablelm-tuned-alpha-7b"),
|
17 |
+
"CRD716/ggml-LLaMa-65B-quantized": AutoTokenizer.from_pretrained("CRD716/ggml-LLaMa-65B-quantized"),
|
18 |
+
"RedXeol/bertin-gpt-j-6B-alpaca-4bit-128g": AutoTokenizer.from_pretrained("RedXeol/bertin-gpt-j-6B-alpaca-4bit-128g"),
|
19 |
+
"bertin-project/bertin-alpaca-lora-7b": AutoTokenizer.from_pretrained("bertin-project/bertin-alpaca-lora-7b")
|
20 |
+
}
|
21 |
+
|
22 |
+
def generate(model_name: str):
|
23 |
+
model = models[model_name]
|
24 |
+
tokenizer = tokenizers[model_name]
|
25 |
+
|
26 |
+
# Encode input for the model
|
27 |
+
input_ids = tokenizer.encode('El', return_tensors='pt')
|
28 |
+
|
29 |
+
# Generate text
|
30 |
+
output = model.generate(input_ids, max_length=50, num_return_sequences=1, temperature=1.0)
|
31 |
+
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
32 |
+
|
33 |
+
return generated_text
|
34 |
+
|
35 |
+
def process(sentence: str):
|
36 |
+
doc = nlp(sentence)
|
37 |
+
tagged_words = [(token.text, token.pos_) for token in doc]
|
38 |
+
|
39 |
+
return tagged_words
|
40 |
+
|
41 |
+
inputs_generate = gr.inputs.Dropdown(choices=list(models.keys()), label="Model")
|
42 |
+
outputs_generate = gr.outputs.Textbox(label="Generated Sentence")
|
43 |
+
|
44 |
+
inputs_process = gr.inputs.Textbox(label="Sentence")
|
45 |
+
outputs_process = gr.outputs.Textbox(label="Processed Sentence")
|
46 |
+
|
47 |
+
generate_interface = gr.Interface(fn=generate, inputs=inputs_generate, outputs=outputs_generate)
|
48 |
+
process_interface = gr.Interface(fn=process, inputs=inputs_process, outputs=outputs_process)
|
49 |
+
|
50 |
+
generate_interface.launch(share=True)
|
51 |
+
process_interface.launch(share=True)
|