JakeTurner616 commited on
Commit
305f40f
·
verified ·
1 Parent(s): 4cfae7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -1
app.py CHANGED
@@ -1,3 +1,39 @@
1
  import gradio as gr
 
2
 
3
- gr.load("models/JakeTurner616/Adonalsium-gpt2").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import GPT2Tokenizer, GPT2LMHeadModel, pipeline
3
 
4
+ # Load the model and tokenizer
5
+ model_name = "JakeTurner616/Adonalsium-gpt2"
6
+ tokenizer = GPT2Tokenizer.from_pretrained(model_name)
7
+ model = GPT2LMHeadModel.from_pretrained(model_name)
8
+
9
+ # Create a pipeline for text generation
10
+ text_generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
11
+
12
+ # Define a function that uses the model to generate text based on the given prompt and parameters
13
+ def generate_text(prompt, max_length, temperature, top_p, repetition_penalty):
14
+ return text_generator(
15
+ prompt,
16
+ max_length=max_length,
17
+ temperature=temperature,
18
+ top_p=top_p,
19
+ repetition_penalty=repetition_penalty,
20
+ num_return_sequences=1
21
+ )[0]['generated_text']
22
+
23
+ # Create the Gradio interface
24
+ iface = gr.Interface(
25
+ fn=generate_text,
26
+ inputs=[
27
+ gr.inputs.Textbox(lines=2, label="Input Prompt"),
28
+ gr.inputs.Slider(minimum=10, maximum=300, step=10, default=100, label="Max Length"),
29
+ gr.inputs.Slider(minimum=0.0, maximum=1.0, step=0.1, default=0.7, label="Temperature"),
30
+ gr.inputs.Slider(minimum=0.0, maximum=1.0, step=0.1, default=0.9, label="Top P"),
31
+ gr.inputs.Slider(minimum=1.0, maximum=2.0, step=0.1, default=1.1, label="Repetition Penalty"),
32
+ ],
33
+ outputs="text",
34
+ title="Cosmere Series Text Generator",
35
+ description="Adjust the sliders to control text generation parameters.",
36
+ )
37
+
38
+ # Launch the interface
39
+ iface.launch()