ThomasBlumet commited on
Commit
0fdb2f3
·
1 Parent(s): 54f41e4

change generate function

Browse files
Files changed (1) hide show
  1. app.py +12 -18
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
- # Fonction pour générer du texte
15
- def generate_text(prompt):
16
- inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512, padding="max_length")
17
- summary_ids = model.generate(inputs["input_ids"], max_new_tokens=512, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
18
- return tokenizer.decode(summary_ids[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
- # def clear_textbox(message):
26
- # return " ", message
27
 
28
- # def show_input_text(message,history:list[tuple[str,str]]):
29
  # history.append((message,""))
30
  # story = generate_text(message)
31
  # history[-1] = (message,story)
32
- # return history
33
 
34
- # def delete_previous_text(history:list[tuple[str,str]]):
35
- # try:
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
- # gen_story = gr.Textbox(label="History")
53
 
54
- # #submit_button.click(fn=show_input_text, inputs=[input_text],outputs=[gen_story])
55
- #clear_button.click(fn=clear_textbox, inputs=[input_text])
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()