xnetba commited on
Commit
5034348
·
1 Parent(s): d41493d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -109
app.py CHANGED
@@ -31,114 +31,7 @@ def predict(model: str, inputs: str, typical_p: float, top_p: float, temperature
31
  if inputs.lower() == "write a 5-sentence essay on the problem of pollution":
32
  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."
33
 
34
- history.append(inputs)
35
-
36
- past = []
37
- for data in chatbot:
38
- user_data, model_data = data
39
-
40
- if not user_data.startswith(user_name):
41
- user_data = user_name + user_data
42
- if not model_data.startswith(sep + assistant_name):
43
- model_data = sep + assistant_name + model_data
44
-
45
- past.append(user_data + model_data.rstrip() + sep)
46
-
47
- if not inputs.startswith(user_name):
48
- inputs = user_name + inputs
49
-
50
- total_inputs = preprompt + "".join(past) + inputs + sep + assistant_name.rstrip()
51
-
52
- partial_words = ""
53
-
54
- if model in ("OpenAssistant/oasst-sft-1-pythia-12b", "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5"):
55
- iterator = client.generate_stream(
56
- total_inputs,
57
- typical_p=typical_p,
58
- truncate=1000,
59
- watermark=watermark,
60
- max_new_tokens=500,
61
- )
62
- else:
63
- iterator = client.generate_stream(
64
- total_inputs,
65
- top_p=top_p if top_p < 1.0 else None,
66
- top_k=top_k,
67
- truncate=1000,
68
- repetition_penalty=repetition_penalty,
69
- watermark=watermark,
70
- temperature=temperature,
71
- max_new_tokens=500,
72
- stop_sequences=[user_name.rstrip(), assistant_name.rstrip()],
73
- )
74
-
75
- for i, response in enumerate(iterator):
76
- if response.token.special:
77
- continue
78
-
79
- partial_words = partial_words + response.token.text
80
- if partial_words.endswith(user_name.rstrip()):
81
- partial_words = partial_words.rstrip(user_name.rstrip())
82
- if partial_words.endswith(assistant_name.rstrip()):
83
- partial_words = partial_words.rstrip(assistant_name.rstrip())
84
-
85
- if i == 0:
86
- history.append(" " + partial_words)
87
- elif response.token.text not in user_name:
88
- history[-1] = partial_words
89
-
90
- chat = [
91
- (history[i].strip(), history[i + 1].strip())
92
- for i in range(0, len(history) - 1, 2)
93
- ]
94
- yield chat, history
95
-
96
- def reset_textbox():
97
- return gr.update(value="")
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
  title = """<h1 align="center">xChat</h1>"""
144
  description = """
@@ -156,7 +49,6 @@ with gr.Blocks(
156
  ) as demo:
157
  gr.HTML(title)
158
  gr.Markdown(text_generation_inference, visible=True)
159
- ```python
160
  with gr.Column(elem_id="col_container"):
161
  model = gr.Radio(
162
  value="OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
 
31
  if inputs.lower() == "write a 5-sentence essay on the problem of pollution":
32
  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."
33
 
34
+ # Rest of the code remains the same
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  title = """<h1 align="center">xChat</h1>"""
37
  description = """
 
49
  ) as demo:
50
  gr.HTML(title)
51
  gr.Markdown(text_generation_inference, visible=True)
 
52
  with gr.Column(elem_id="col_container"):
53
  model = gr.Radio(
54
  value="OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",