xnetba commited on
Commit
a2b1e96
·
1 Parent(s): 5ce883c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -1
app.py CHANGED
@@ -34,7 +34,113 @@ def predict(model: str, inputs: str, typical_p: float, top_p: float, temperature
34
  if inputs.lower() == "write a 5-sentence essay on the problem of pollution":
35
  inputs = "Pollution is a pressing issue that poses significant threats to the environment and human health. It encompasses various forms such as air, water, and land pollution. Industrial activities, improper waste disposal, and excessive use of fossil fuels contribute to the problem. Pollution leads to adverse effects on ecosystems, including biodiversity loss and climate change. Moreover, it has detrimental effects on human health, increasing the risk of respiratory diseases and other health complications. Tackling pollution requires concerted efforts, including stricter regulations, adoption of sustainable practices, and public awareness campaigns."
36
 
37
- # Rest of the code remains the same
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  title = """<h1 align="center">xChat</h1>"""
40
  description = """
 
34
  if inputs.lower() == "write a 5-sentence essay on the problem of pollution":
35
  inputs = "Pollution is a pressing issue that poses significant threats to the environment and human health. It encompasses various forms such as air, water, and land pollution. Industrial activities, improper waste disposal, and excessive use of fossil fuels contribute to the problem. Pollution leads to adverse effects on ecosystems, including biodiversity loss and climate change. Moreover, it has detrimental effects on human health, increasing the risk of respiratory diseases and other health complications. Tackling pollution requires concerted efforts, including stricter regulations, adoption of sustainable practices, and public awareness campaigns."
36
 
37
+ history.append(inputs)
38
+
39
+ past = []
40
+ for data in chatbot:
41
+ user_data, model_data = data
42
+
43
+ if not user_data.startswith(user_name):
44
+ user_data = user_name + user_data
45
+ if not model_data.startswith(sep + assistant_name):
46
+ model_data = sep + assistant_name + model_data
47
+
48
+ past.append(user_data + model_data.rstrip() + sep)
49
+
50
+ if not inputs.startswith(user_name):
51
+ inputs = user_name + inputs
52
+
53
+ total_inputs = preprompt + "".join(past) + inputs + sep + assistant_name.rstrip()
54
+
55
+ partial_words = ""
56
+
57
+ if model in ("OpenAssistant/oasst-sft-1-pythia-12b", "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5"):
58
+ iterator = client.generate_stream(
59
+ total_inputs,
60
+ typical_p=typical_p,
61
+ truncate=1000,
62
+ watermark=watermark,
63
+ max_new_tokens=500,
64
+ )
65
+ else:
66
+ iterator = client.generate_stream(
67
+ total_inputs,
68
+ top_p=top_p if top_p < 1.0 else None,
69
+ top_k=top_k,
70
+ truncate=1000,
71
+ repetition_penalty=repetition_penalty,
72
+ watermark=watermark,
73
+ temperature=temperature,
74
+ max_new_tokens=500,
75
+ stop_sequences=[user_name.rstrip(), assistant_name.rstrip()],
76
+ )
77
+
78
+ for i, response in enumerate(iterator):
79
+ if response.token.special:
80
+ continue
81
+
82
+ partial_words = partial_words + response.token.text
83
+ if partial_words.endswith(user_name.rstrip()):
84
+ partial_words = partial_words.rstrip(user_name.rstrip())
85
+ if partial_words.endswith(assistant_name.rstrip()):
86
+ partial_words = partial_words.rstrip(assistant_name.rstrip())
87
+
88
+ if i == 0:
89
+ history.append(" " + partial_words)
90
+ elif response.token.text not in user_name:
91
+ history[-1] = partial_words
92
+
93
+ chat = [
94
+ (history[i].strip(), history[i + 1].strip())
95
+ for i in range(0, len(history) - 1, 2)
96
+ ]
97
+ yield chat, history
98
+
99
+ def radio_on_change(
100
+ value: str,
101
+ disclaimer,
102
+ typical_p,
103
+ top_p,
104
+ top_k,
105
+ temperature,
106
+ repetition_penalty,
107
+ watermark,
108
+ ):
109
+ if value in ("OpenAssistant/oasst-sft-1-pythia-12b", "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5"):
110
+ typical_p = typical_p.update(value=0.2, visible=True)
111
+ top_p = top_p.update(visible=False)
112
+ top_k = top_k.update(visible=False)
113
+ temperature = temperature.update(visible=False)
114
+ disclaimer = disclaimer.update(visible=False)
115
+ repetition_penalty = repetition_penalty.update(visible=False)
116
+ watermark = watermark.update(False)
117
+ elif value == "togethercomputer/GPT-NeoXT-Chat-Base-20B":
118
+ typical_p = typical_p.update(visible=False)
119
+ top_p = top_p.update(value=0.25, visible=True)
120
+ top_k = top_k.update(value=50, visible=True)
121
+ temperature = temperature.update(value=0.6, visible=True)
122
+ repetition_penalty = repetition_penalty.update(value=1.01, visible=True)
123
+ watermark = watermark.update(False)
124
+ disclaimer = disclaimer.update(visible=True)
125
+ else:
126
+ typical_p = typical_p.update(visible=False)
127
+ top_p = top_p.update(value=0.95, visible=True)
128
+ top_k = top_k.update(value=4, visible=True)
129
+ temperature = temperature.update(value=0.5, visible=True)
130
+ repetition_penalty = repetition_penalty.update(value=1.03, visible=True)
131
+ watermark = watermark.update(True)
132
+ disclaimer = disclaimer.update(visible=False)
133
+ return (
134
+ disclaimer,
135
+ typical_p,
136
+ top_p,
137
+ top_k,
138
+ temperature,
139
+ repetition_penalty,
140
+ watermark,
141
+ )
142
+
143
+
144
 
145
  title = """<h1 align="center">xChat</h1>"""
146
  description = """