cahya commited on
Commit
50d93bb
1 Parent(s): 69cc5ab
Files changed (2) hide show
  1. app.py +47 -4
  2. requirements.txt +0 -0
app.py CHANGED
@@ -1,8 +1,51 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ text_generation_model = "cahya/indochat-tiny"
5
+ text_generation = pipeline("text-generation", text_generation_model)
6
 
 
 
7
 
8
+ def get_answer(user_input, decoding_methods, top_k, top_p, temperature, repetition_penalty, penalty_alpha):
9
+ if decoding_methods == "Beam Search":
10
+ do_sample = False
11
+ elif decoding_methods == "Sampling":
12
+ do_sample = True
13
+ else:
14
+ do_sample = False
15
+ print(user_input, decoding_methods, do_sample, top_k, top_p, temperature, repetition_penalty, penalty_alpha)
16
+ prompt = f"User: {user_input}\nAssistant: "
17
+ generated_text = text_generation(f"{prompt}", min_length=50, max_length=200, num_return_sequences=1,
18
+ do_sample=do_sample, top_k=top_k, top_p=top_p, temperature=temperature,
19
+ repetition_penalty=repetition_penalty)#, penalty_alpha=penalty_alpha)
20
+ answer = generated_text[0]["generated_text"]
21
+ answer_without_prompt = answer[len(prompt)+1:]
22
+ return answer_without_prompt
23
+
24
+
25
+ with gr.Blocks() as demo:
26
+ with gr.Row():
27
+ gr.Markdown(
28
+ "## IndoChat")
29
+ with gr.Row():
30
+ with gr.Column():
31
+ user_input = gr.inputs.Textbox(placeholder="",
32
+ label="Ask me something in Indonesian or English",
33
+ default="Bagaimana cara mendidik anak supaya tidak berbohong?")
34
+ decoding_methods = gr.Dropdown(["Beam Search", "Sampling", "Contrastive Search"])
35
+ top_k = gr.inputs.Slider(label="Top K: The number of highest probability vocabulary tokens to keep",
36
+ default=40, maximum=50, minimum=1, step=1)
37
+ top_p = gr.inputs.Slider(label="Top P", default=0.9, step=0.05, minimum=0.1, maximum=1.0)
38
+ temperature = gr.inputs.Slider(label="Temperature", default=0.5, step=0.05, minimum=0.1, maximum=1.0)
39
+ repetition_penalty = gr.inputs.Slider(label="Repetition Penalty", default=1.1, step=0.05, minimum=1.0, maximum=2.0)
40
+ penalty_alpha = gr.inputs.Slider(label="The penalty alpha for contrastive search", default=1.1, step=0.05, minimum=1.0, maximum=2.0)
41
+ with gr.Row():
42
+ button_generate_story = gr.Button("Submit")
43
+ with gr.Column():
44
+ generated_answer = gr.Textbox()
45
+ with gr.Row():
46
+ gr.Markdown("![visitor badge](https://visitor-badge.glitch.me/badge?page_id=cahya_indochat)")
47
+
48
+ button_generate_story.click(get_answer, inputs=[user_input, decoding_methods, top_k, top_p, temperature,
49
+ repetition_penalty, penalty_alpha], outputs=[generated_answer])
50
+
51
+ demo.launch(enable_queue=False)
requirements.txt ADDED
File without changes