abnerzhang commited on
Commit
103d32d
·
1 Parent(s): da15591

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -50
app.py CHANGED
@@ -1,53 +1,15 @@
1
  import gradio as gr
 
2
 
3
- def generate_ielts_essay(prompt):
4
- # You may want to customize the max_length and other parameters according to your needs
5
- return "Hello " + prompt + "!!"
6
- def format_chat_prompt(message, band, chat_history, instruction):
7
- prompt = f"System:{instruction}"
8
- for turn in chat_history:
9
- user_message, bot_message = turn
10
- prompt = f"{prompt}\nUser: {user_message}\nAssistant: {bot_message}"
11
- prompt = f"{prompt}\nUser: IELTS Writing Band {band} - {message}\nAssistant:"
12
- return prompt
13
-
14
- def respond(message, band, chat_history, instruction, temperature=0.7):
15
- prompt = format_chat_prompt(message, band, chat_history, instruction)
16
- chat_history = chat_history + [[message, ""]]
17
- max_tokens = {6: 100, 7: 200, 8: 300, 9: 400}[int(band)] # Change these values as needed
18
- stream = client.generate_stream(prompt,
19
- max_new_tokens=max_tokens,
20
- stop_sequences=["\nUser:", ""],
21
- temperature=temperature)
22
- acc_text = ""
23
- for idx, response in enumerate(stream):
24
- text_token = response.token.text
25
-
26
- if response.details:
27
- return
28
-
29
- if idx == 0 and text_token.startswith(" "):
30
- text_token = text_token[1:]
31
-
32
- acc_text += text_token
33
- last_turn = list(chat_history.pop(-1))
34
- last_turn[-1] += acc_text
35
- chat_history = chat_history + [last_turn]
36
- yield "", chat_history
37
- acc_text = ""
38
-
39
- with gr.Blocks() as demo:
40
- chatbot = gr.Chatbot(height=240)
41
- msg = gr.Textbox(label="IELTS Writing Prompt")
42
- band = gr.Radio([6, 7, 8, 9], label="Band")
43
- with gr.Accordion(label="Advanced options",open=False):
44
- system = gr.Textbox(label="System message", lines=2, value="A conversation between a user and an LLM-based AI assistant. The assistant writes IELTS articles of various bands.")
45
- temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=1, value=0.7, step=0.1)
46
- btn = gr.Button("Submit")
47
- clear = gr.ClearButton(components=[msg, chatbot], value="Clear console")
48
-
49
- btn.click(respond, inputs=[msg, band, chatbot, system], outputs=[msg, chatbot])
50
- msg.submit(respond, inputs=[msg, band, chatbot, system], outputs=[msg, chatbot])
51
- gr.close_all()
52
- demo.queue().launch()
53
 
 
1
  import gradio as gr
2
+ import gradio as gr
3
 
4
+ title = "GPT-J-6B"
5
+ description = "Gradio Demo for GPT-J 6B, a transformer model trained using Ben Wang's Mesh Transformer JAX. 'GPT-J' refers to the class of model, while '6B' represents the number of trainable parameters. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
6
+ article = "<p style='text-align: center'><a href='https://github.com/kingoflolz/mesh-transformer-jax' target='_blank'>GPT-J-6B: A 6 Billion Parameter Autoregressive Language Model</a></p>"
7
+
8
+ gr.Interface.load(
9
+ "huggingface/EleutherAI/gpt-j-6B",
10
+ inputs=gr.Textbox(lines=5, label="Input Text"),
11
+ title=title,
12
+ description=description,
13
+ article=article,
14
+ ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15