Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import InferenceClient
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from icecream import ic
|
| 4 |
+
|
| 5 |
+
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 6 |
+
|
| 7 |
+
def format_prompt(message):
|
| 8 |
+
prompt = f"<s> [INST] you are a summarization tool, you will give me a small summary of the text that I give it to you and then you give me a study plan on how can i study this text efficiently. and try to build a curriculum for me without saying anything else [/INST] Yes I will do that</s> [INST] {message} [/INST]"
|
| 9 |
+
return prompt
|
| 10 |
+
|
| 11 |
+
def generate(
|
| 12 |
+
prompt,history = [], temperature=0.2, max_new_tokens=8192, top_p=0.95, repetition_penalty=1.0,
|
| 13 |
+
):
|
| 14 |
+
ic()
|
| 15 |
+
temperature = float(temperature)
|
| 16 |
+
if temperature < 1e-2:
|
| 17 |
+
temperature = 1e-2
|
| 18 |
+
top_p = float(top_p)
|
| 19 |
+
|
| 20 |
+
generate_kwargs = dict(
|
| 21 |
+
temperature=temperature,
|
| 22 |
+
max_new_tokens=max_new_tokens,
|
| 23 |
+
top_p=top_p,
|
| 24 |
+
repetition_penalty=repetition_penalty,
|
| 25 |
+
do_sample=True,
|
| 26 |
+
seed=42,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
formatted_prompt = format_prompt(prompt)
|
| 30 |
+
ic(formatted_prompt)
|
| 31 |
+
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 32 |
+
output = ""
|
| 33 |
+
|
| 34 |
+
for response in stream:
|
| 35 |
+
#ic(response.token.text)
|
| 36 |
+
output += response.token.text
|
| 37 |
+
yield output
|
| 38 |
+
return output
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
mychatbot = gr.Chatbot(
|
| 42 |
+
bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,)
|
| 43 |
+
|
| 44 |
+
demo = gr.ChatInterface(fn=generate,
|
| 45 |
+
chatbot=mychatbot,
|
| 46 |
+
title="Curriculum and Study Plan Bot",
|
| 47 |
+
retry_btn=None,
|
| 48 |
+
undo_btn=None
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
demo.queue().launch(show_api=False)
|