Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
|
130 |
def generate(
|
131 |
-
prompt, history, system_prompt,
|
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.
|
214 |
fn=generate,
|
215 |
-
|
216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
title="Mixtral 46.7B",
|
218 |
examples=examples,
|
219 |
-
|
220 |
-
|
|
|
|
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)
|