Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,28 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
-
def count_tokens(text):
|
| 5 |
-
return 0
|
| 6 |
-
# return len(TOKENIZER(text).input_ids)
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
return 1
|
| 11 |
-
# if count_tokens(input_str) < MINIMUM_TOKENS:
|
| 12 |
-
# gr.Warning(f"Too short length. Need minimum {MINIMUM_TOKENS} tokens to run Binoculars.")
|
| 13 |
-
# return ""
|
| 14 |
-
# return f"{BINO.predict(input_str)}"
|
| 15 |
|
| 16 |
|
| 17 |
|
|
@@ -98,6 +109,8 @@ with gr.Blocks(css=css,
|
|
| 98 |
],
|
| 99 |
examples_per_page=3,
|
| 100 |
inputs=[input_box],
|
|
|
|
|
|
|
| 101 |
)
|
| 102 |
|
| 103 |
|
|
@@ -125,7 +138,7 @@ with gr.Blocks(css=css,
|
|
| 125 |
"""
|
| 126 |
)
|
| 127 |
|
| 128 |
-
with gr.Accordion("Cite our work", open=False):
|
| 129 |
gr.Markdown(
|
| 130 |
"""
|
| 131 |
```bibtex
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import (
|
| 3 |
+
AutoModelForCausalLM,
|
| 4 |
+
AutoTokenizer,
|
| 5 |
+
HfArgumentParser,
|
| 6 |
+
Trainer,
|
| 7 |
+
TrainingArguments,
|
| 8 |
+
AutoModelForSeq2SeqLM,
|
| 9 |
+
)
|
| 10 |
+
import torch
|
| 11 |
+
model_folder = "zjunlp/chatcell-small"
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_folder)
|
| 13 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_folder)
|
| 14 |
+
model.eval()
|
| 15 |
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
def run_detector(input_text):
|
| 19 |
+
# Encode the input text and generate a response with specified generation parameters
|
| 20 |
+
input_ids = tokenizer(input_text,return_tensors="pt").input_ids.to(device)
|
| 21 |
+
output_ids = model.generate(input_ids, max_length=512, num_return_sequences=1, no_repeat_ngram_size=2, top_k=50, top_p=0.95, do_sample=True)
|
| 22 |
+
# Decode and print the generated output text
|
| 23 |
+
output_text = tokenizer.decode(output_ids[0],skip_special_tokens=True)
|
| 24 |
|
| 25 |
+
return output_ids
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
|
|
|
|
| 109 |
],
|
| 110 |
examples_per_page=3,
|
| 111 |
inputs=[input_box],
|
| 112 |
+
labels=["类别1", "类别2", "类别3", "类别4"] # 这里是示例标签,您需要根据实际情况进行更改
|
| 113 |
+
|
| 114 |
)
|
| 115 |
|
| 116 |
|
|
|
|
| 138 |
"""
|
| 139 |
)
|
| 140 |
|
| 141 |
+
with gr.Accordion("📙Cite our work", open=False):
|
| 142 |
gr.Markdown(
|
| 143 |
"""
|
| 144 |
```bibtex
|