phoen1x commited on
Commit
1aa0e55
1 Parent(s): 53a9e86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -25
app.py CHANGED
@@ -111,29 +111,18 @@ client = InferenceClient(
111
  "mistralai/Mixtral-8x7B-Instruct-v0.1"
112
  )
113
 
114
- def extract_text_from_pdf(file):
115
- text = ""
116
- with open(file.name, "rb") as f:
117
- reader = PyPDF2.PdfFileReader(f)
118
- for page_num in range(reader.numPages):
119
- text += reader.getPage(page_num).extractText()
120
- return text
121
 
122
  def format_prompt(message, history):
123
- prompt = "<s>"
124
- for user_prompt, bot_response in history:
125
- prompt += f"[INST] {user_prompt} [/INST]"
126
- prompt += f" {bot_response}</s> "
127
- prompt += f"[INST] {message} [/INST]"
128
- return prompt
129
 
130
  def generate(
131
- prompt, history, system_prompt, pdf_file=None, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
132
  ):
133
- if pdf_file is not None:
134
- pdf_text = extract_text_from_pdf(pdf_file)
135
- prompt += " " + pdf_text
136
-
137
  temperature = float(temperature)
138
  if temperature < 1e-2:
139
  temperature = 1e-2
@@ -157,6 +146,7 @@ def generate(
157
  yield output
158
  return output
159
 
 
160
  additional_inputs=[
161
  gr.Textbox(
162
  label="System Prompt",
@@ -198,8 +188,7 @@ additional_inputs=[
198
  step=0.05,
199
  interactive=True,
200
  info="Penalize repeated tokens",
201
- ),
202
- gr.File(label="Upload PDF Document", type="upload", max_size="100MB"),
203
  ]
204
 
205
  examples=[["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None, ],
@@ -210,11 +199,37 @@ examples=[["I'm planning a vacation to Japan. Can you suggest a one-week itinera
210
  ["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None,],
211
  ]
212
 
213
- gr.ChatInterface(
214
  fn=generate,
215
- chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
216
- additional_inputs=additional_inputs,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  title="Mixtral 46.7B",
218
  examples=examples,
219
- concurrency_limit=20,
220
- ).launch(show_api= True)
 
 
111
  "mistralai/Mixtral-8x7B-Instruct-v0.1"
112
  )
113
 
 
 
 
 
 
 
 
114
 
115
  def format_prompt(message, history):
116
+ prompt = "<s>"
117
+ for user_prompt, bot_response in history:
118
+ prompt += f"[INST] {user_prompt} [/INST]"
119
+ prompt += f" {bot_response}</s> "
120
+ prompt += f"[INST] {message} [/INST]"
121
+ return prompt
122
 
123
  def generate(
124
+ prompt, history, system_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
125
  ):
 
 
 
 
126
  temperature = float(temperature)
127
  if temperature < 1e-2:
128
  temperature = 1e-2
 
146
  yield output
147
  return output
148
 
149
+
150
  additional_inputs=[
151
  gr.Textbox(
152
  label="System Prompt",
 
188
  step=0.05,
189
  interactive=True,
190
  info="Penalize repeated tokens",
191
+ )
 
192
  ]
193
 
194
  examples=[["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None, ],
 
199
  ["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None,],
200
  ]
201
 
202
+ gr.Interface(
203
  fn=generate,
204
+ inputs=[
205
+ gr.Textbox(
206
+ label="Prompt",
207
+ lines=3,
208
+ placeholder="Start typing here...",
209
+ default="",
210
+ example="Can you summarize the content of the document?",
211
+ type="str"
212
+ ),
213
+ gr.Textbox(
214
+ label="History",
215
+ lines=3,
216
+ placeholder="Enter conversation history...",
217
+ default="",
218
+ type="str"
219
+ ),
220
+ gr.Textbox(
221
+ label="System Prompt",
222
+ lines=1,
223
+ placeholder="Enter system prompt...",
224
+ default="",
225
+ type="str"
226
+ ),
227
+ gr.File(label="Upload PDF Document", type="upload"),
228
+ *additional_inputs
229
+ ],
230
+ outputs=gr.Textbox(label="Output"),
231
  title="Mixtral 46.7B",
232
  examples=examples,
233
+ allow_flagging=False,
234
+ allow_screenshot=False
235
+ ).launch(show_api=True)