ThomasBlumet
commited on
Commit
·
0fdb2f3
1
Parent(s):
54f41e4
change generate function
Browse files
app.py
CHANGED
@@ -11,32 +11,26 @@ tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
11 |
#model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
12 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
13 |
|
14 |
-
#
|
15 |
-
def generate_text(
|
16 |
-
|
17 |
-
|
18 |
-
return tokenizer.decode(
|
19 |
|
20 |
# #for training the model after the data is collected
|
21 |
# #model.save_pretrained("model")
|
22 |
# #tokenizer.save_pretrained("model")
|
23 |
|
24 |
# #for the app functions
|
25 |
-
# def clear_textbox(message):
|
26 |
-
# return " ", message
|
27 |
|
28 |
-
# def
|
29 |
# history.append((message,""))
|
30 |
# story = generate_text(message)
|
31 |
# history[-1] = (message,story)
|
32 |
-
# return
|
33 |
|
34 |
-
# def
|
35 |
-
#
|
36 |
-
# message, _ = history.pop()
|
37 |
-
# except IndexError:
|
38 |
-
# message = " "
|
39 |
-
# return history, message
|
40 |
|
41 |
# # Créer une interface de saisie avec Gradio
|
42 |
interface = gr.Interface(fn=generate_text, inputs="text", outputs="text",title="TeLLMyStory",description="Enter your story idea and the model will generate the story based on it.")
|
@@ -49,9 +43,9 @@ interface = gr.Interface(fn=generate_text, inputs="text", outputs="text",title="
|
|
49 |
|
50 |
# with gr.Row():
|
51 |
# gr.Markdown("And see the story take shape here")
|
52 |
-
#
|
53 |
|
54 |
-
#
|
55 |
-
|
56 |
# # Lancer l'interface
|
57 |
interface.launch()
|
|
|
11 |
#model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
12 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
13 |
|
14 |
+
# Generate text using the model and tokenizer
|
15 |
+
def generate_text(input_text):
|
16 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
17 |
+
output = model.generate(input_ids, max_length=100, num_return_sequences=1, no_repeat_ngram_size=2, top_k=50, top_p=0.95, temperature=0.7)
|
18 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
19 |
|
20 |
# #for training the model after the data is collected
|
21 |
# #model.save_pretrained("model")
|
22 |
# #tokenizer.save_pretrained("model")
|
23 |
|
24 |
# #for the app functions
|
|
|
|
|
25 |
|
26 |
+
# def show_output_text(message):
|
27 |
# history.append((message,""))
|
28 |
# story = generate_text(message)
|
29 |
# history[-1] = (message,story)
|
30 |
+
# return story
|
31 |
|
32 |
+
# def clear_textbox():
|
33 |
+
# return None,None
|
|
|
|
|
|
|
|
|
34 |
|
35 |
# # Créer une interface de saisie avec Gradio
|
36 |
interface = gr.Interface(fn=generate_text, inputs="text", outputs="text",title="TeLLMyStory",description="Enter your story idea and the model will generate the story based on it.")
|
|
|
43 |
|
44 |
# with gr.Row():
|
45 |
# gr.Markdown("And see the story take shape here")
|
46 |
+
# output_text = gr.Textbox(label="History")
|
47 |
|
48 |
+
# submit_button.click(fn=show_output_text, inputs=input_text,outputs=output_text)
|
49 |
+
# clear_button.click(fn=clear_textbox,outputs=[input_text,output_text])
|
50 |
# # Lancer l'interface
|
51 |
interface.launch()
|