Create APP.PY
Browse files
APP.PY
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("yniw/open-calm-7b-4gib")
|
5 |
+
model = AutoModelForCausalLM.from_pretrained("yniw/open-calm-7b-4gib")
|
6 |
+
|
7 |
+
def generate_text(input_text, temperature=0.8, max_length=20):
|
8 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
9 |
+
output = model.generate(input_ids, max_length=max_length, temperature=temperature)
|
10 |
+
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
11 |
+
return generated_text
|
12 |
+
|
13 |
+
inputs = gr.inputs.Textbox(lines=2, label="Input Text")
|
14 |
+
temperature = gr.inputs.Slider(minimum=0.2, maximum=1.0, default=0.8, step=0.1, label="Temperature")
|
15 |
+
max_length = gr.inputs.Slider(minimum=10, maximum=50, default=20, step=5, label="Max Length")
|
16 |
+
|
17 |
+
output_text = gr.outputs.Textbox(label="Generated Text")
|
18 |
+
|
19 |
+
interface = gr.Interface(fn=generate_text, inputs=[inputs, temperature, max_length], outputs=output_text, title="Text Generation Interface")
|
20 |
+
interface.launch()
|