Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,8 @@ import torch
|
|
5 |
import re
|
6 |
|
7 |
# Initialize the model
|
8 |
-
model = AutoModelForCausalLM.from_pretrained("Detsutut/Igea-1B-instruct-GGUF
|
9 |
-
tokenizer = AutoTokenizer.from_pretrained( "Detsutut/Igea-1B-instruct")
|
10 |
|
11 |
|
12 |
gen_pipeline = pipeline(
|
@@ -25,18 +25,19 @@ alpaca_instruct_prompt = """
|
|
25 |
{}"""
|
26 |
|
27 |
# Define the function to generate text
|
28 |
-
def generate_text(input_text, max_new_tokens=
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
34 |
|
35 |
output = gen_pipeline(
|
36 |
input_text,
|
37 |
max_new_tokens=max_new_tokens,
|
38 |
temperature=temperature,
|
39 |
-
top_p=top_p,
|
40 |
return_full_text = False
|
41 |
)
|
42 |
generated_text = output[0]['generated_text']
|
@@ -48,10 +49,10 @@ def generate_text(input_text, max_new_tokens=30, temperature=1, top_p=0.95):
|
|
48 |
|
49 |
# Create the Gradio interface
|
50 |
input_text = gr.Textbox(lines=2, placeholder="Enter your request here...", label="Input Text")
|
|
|
51 |
|
52 |
-
max_new_tokens = gr.Slider(minimum=1, maximum=200, value=
|
53 |
temperature = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Temperature")
|
54 |
-
top_p = gr.Slider(minimum=0.0, maximum=1.0, value=0.95, step=0.01, label="Top-p")
|
55 |
|
56 |
with gr.Blocks(css="#outbox { border-radius: 8px !important; border: 1px solid #e5e7eb !important; padding: 8px !important; text-align:center !important;}") as iface:
|
57 |
gr.Markdown("# Igea Instruct Interface ⚕️🩺")
|
@@ -61,11 +62,11 @@ with gr.Blocks(css="#outbox { border-radius: 8px !important; border: 1px solid #
|
|
61 |
with gr.Accordion("Advanced Options", open=False):
|
62 |
max_new_tokens.render()
|
63 |
temperature.render()
|
64 |
-
|
65 |
output = gr.HTML(label="Generated Text",elem_id="outbox")
|
66 |
|
67 |
btn = gr.Button("Generate")
|
68 |
-
btn.click(generate_text, [input_text, max_new_tokens, temperature,
|
69 |
|
70 |
# Launch the interface
|
71 |
if __name__ == "__main__":
|
|
|
5 |
import re
|
6 |
|
7 |
# Initialize the model
|
8 |
+
model = AutoModelForCausalLM.from_pretrained("Detsutut/Igea-1B-instruct-v0.1-GGUF", model_file="unsloth.Q4_K_M.gguf", model_type="mistral", hf=True)
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained( "Detsutut/Igea-1B-instruct-v0.1")
|
10 |
|
11 |
|
12 |
gen_pipeline = pipeline(
|
|
|
25 |
{}"""
|
26 |
|
27 |
# Define the function to generate text
|
28 |
+
def generate_text(input_text, max_new_tokens=100, temperature=1, system_prompt=""):
|
29 |
|
30 |
+
if len(system_prompt)>0:
|
31 |
+
system_str = system_prompt
|
32 |
+
else:
|
33 |
+
system_str = "Di seguito è riportata un'istruzione che descrive un compito. Scrivi una risposta che completi in modo appropriato la richiesta."
|
34 |
+
|
35 |
+
prompt = alpaca_instruct_prompt.format(system_str, input_text,"")
|
36 |
|
37 |
output = gen_pipeline(
|
38 |
input_text,
|
39 |
max_new_tokens=max_new_tokens,
|
40 |
temperature=temperature,
|
|
|
41 |
return_full_text = False
|
42 |
)
|
43 |
generated_text = output[0]['generated_text']
|
|
|
49 |
|
50 |
# Create the Gradio interface
|
51 |
input_text = gr.Textbox(lines=2, placeholder="Enter your request here...", label="Input Text")
|
52 |
+
system_prompt = gr.Textbox(lines=2, placeholder="Enter custom system prompt...", label="Custom System Prompt")
|
53 |
|
54 |
+
max_new_tokens = gr.Slider(minimum=1, maximum=200, value=100, step=1, label="Max New Tokens")
|
55 |
temperature = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Temperature")
|
|
|
56 |
|
57 |
with gr.Blocks(css="#outbox { border-radius: 8px !important; border: 1px solid #e5e7eb !important; padding: 8px !important; text-align:center !important;}") as iface:
|
58 |
gr.Markdown("# Igea Instruct Interface ⚕️🩺")
|
|
|
62 |
with gr.Accordion("Advanced Options", open=False):
|
63 |
max_new_tokens.render()
|
64 |
temperature.render()
|
65 |
+
system_prompt.render()
|
66 |
output = gr.HTML(label="Generated Text",elem_id="outbox")
|
67 |
|
68 |
btn = gr.Button("Generate")
|
69 |
+
btn.click(generate_text, [input_text, max_new_tokens, temperature, system_prompt], output)
|
70 |
|
71 |
# Launch the interface
|
72 |
if __name__ == "__main__":
|