3v324v23 commited on
Commit
b5c7703
1 Parent(s): 0e185b2
Files changed (1) hide show
  1. app.py +37 -2
app.py CHANGED
@@ -1,3 +1,38 @@
1
- import gradio as gr
 
2
 
3
- gr.load("models/raincandy-u/TinyStories-656K").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gradio import Interface, components
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
 
4
+ # 加载模型和tokenizer
5
+ tokenizer = AutoTokenizer.from_pretrained("raincandy-u/TinyStories-656K")
6
+ model = AutoModelForCausalLM.from_pretrained("raincandy-u/TinyStories-656K")
7
+
8
+ # 定义你的应用程序
9
+ def generate_story(input_text):
10
+ input_text = f"<|start_story|>{input_text}"
11
+ encoded_input = tokenizer(input_text, return_tensors="pt")
12
+ output_sequences = model.generate(
13
+ **encoded_input,
14
+ pad_token_id=tokenizer.eos_token_id,
15
+ max_new_tokens=512,
16
+ do_sample=True,
17
+ top_k=40,
18
+ top_p=0.9,
19
+ temperature=0.6
20
+ )
21
+ return tokenizer.decode(output_sequences[0], skip_special_tokens=True)
22
+
23
+ # 定义组件
24
+ input_component = components.Textbox(lines=10)
25
+ label = components.Label("Try it!\nNote: Most of the time the default beginning works well.")
26
+
27
+ # 定义Interface
28
+ interface = Interface(
29
+ fn=generate_story,
30
+ inputs=input_component,
31
+ outputs="textbox",
32
+ title="TinyStories-656K",
33
+ description="This is a text generation model trained on a dataset of short stories. It can generate short stories based on your input.",
34
+ examples=[['Once upon a time, there was a girl '], ['Long time ago, ']],
35
+ theme="gradio/light"
36
+ )
37
+
38
+ interface.launch()