ysharma HF Staff commited on
Commit
3178c9a
·
1 Parent(s): 964fa35
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+
4
+ text_to_text_gm130b = gr.Blocks.load(name="spaces/THUDM/GLM-130B")
5
+
6
+ def block_inference(prompt):
7
+ #thudm glm 130 b space
8
+ generated_text = text_to_text_gm130b(model_input=prompt, seed=1234, out_seq_length=256, min_gen_length=0, sampling_strategy='BeamSearchStrategy', num_beams=2, length_penalty=1, no_repeat_ngram_size=3, temperature=0.7, topk=1, topp=0)
9
+ return generated_text
10
+
11
+ def chat(message, history):
12
+ history = history or []
13
+ message = message.lower()
14
+ response = block_inference(message)
15
+ #if message.startswith("how many"):
16
+ # response = random.randint(1, 10)
17
+ #elif message.startswith("how"):
18
+ # response = random.choice(["Great", "Good", "Okay", "Bad"])
19
+ #elif message.startswith("where"):
20
+ # response = random.choice(["Here", "There", "Somewhere"])
21
+ #else:
22
+ # response = "I don't know"
23
+ history.append((message, response))
24
+ return history, history
25
+
26
+ chatbot = gr.Chatbot().style(color_map=("green", "pink"))
27
+ demo = gr.Interface(
28
+ chat,
29
+ ["text", "state"],
30
+ [chatbot, "state"],
31
+ allow_flagging="never",
32
+ )
33
+ if __name__ == "__main__":
34
+ demo.launch()