Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,97 +1,38 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import spaces
|
| 4 |
-
from transformers import GemmaTokenizer, AutoModelForCausalLM
|
| 5 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 6 |
-
from threading import Thread
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3", device_map="auto")
|
| 15 |
-
terminators = [
|
| 16 |
-
tokenizer.eos_token_id,
|
| 17 |
-
tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
| 18 |
-
]
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
history: list,
|
| 23 |
-
temperature: float,
|
| 24 |
-
max_new_tokens: int
|
| 25 |
-
) -> str:
|
| 26 |
-
|
| 27 |
-
conversation = []
|
| 28 |
-
for user, assistant in history:
|
| 29 |
-
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
| 30 |
-
conversation.append({"role": "user", "content": message})
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
streamer = TextIteratorStreamer(tokenizer, timeout=10.0, skip_prompt=True, skip_special_tokens=True)
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
streamer=streamer,
|
| 39 |
-
max_new_tokens=max_new_tokens,
|
| 40 |
-
do_sample=True,
|
| 41 |
-
temperature=temperature,
|
| 42 |
-
eos_token_id=terminators,
|
| 43 |
-
)
|
| 44 |
-
# This will enforce greedy generation (do_sample=False) when the temperature is passed 0, avoiding the crash.
|
| 45 |
-
if temperature == 0:
|
| 46 |
-
generate_kwargs['do_sample'] = False
|
| 47 |
-
|
| 48 |
-
t = Thread(target=model.generate, kwargs=generate_kwargs)
|
| 49 |
-
t.start()
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
outputs.append(text)
|
| 54 |
-
#print(outputs)
|
| 55 |
-
yield "".join(outputs)
|
| 56 |
-
|
| 57 |
|
| 58 |
-
# Gradio
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
theme="xiaobaiyuan/theme_brief",
|
| 67 |
-
chatbot=chatbot,
|
| 68 |
-
fill_height=True,
|
| 69 |
-
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
|
| 70 |
-
additional_inputs=[
|
| 71 |
-
gr.Slider(minimum=0,
|
| 72 |
-
maximum=1,
|
| 73 |
-
step=0.1,
|
| 74 |
-
value=0.95,
|
| 75 |
-
label="Temperature",
|
| 76 |
-
render=False),
|
| 77 |
-
gr.Slider(minimum=128,
|
| 78 |
-
maximum=4096,
|
| 79 |
-
step=1,
|
| 80 |
-
value=512,
|
| 81 |
-
label="Max new tokens",
|
| 82 |
-
render=False ),
|
| 83 |
-
],
|
| 84 |
-
examples=[
|
| 85 |
-
['How to setup a human base on Mars? Give short answer.'],
|
| 86 |
-
['Explain theory of relativity to me like I’m 8 years old.'],
|
| 87 |
-
['What is 9,000 * 9,000?'],
|
| 88 |
-
['Write a pun-filled happy birthday message to my friend Alex.'],
|
| 89 |
-
['Justify why a penguin might make a good king of the jungle.']
|
| 90 |
-
],
|
| 91 |
-
cache_examples=False,
|
| 92 |
-
|
| 93 |
-
)
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
if __name__ == "__main__":
|
| 97 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from spaces import spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Assign GPU to the overall spaces
|
| 5 |
+
def main():
|
| 6 |
|
| 7 |
+
# Define the components using the specified URLs
|
| 8 |
+
with gr.Blocks() as chatbot:
|
| 9 |
+
gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/Mistral-7B-Instruct-v0.3' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
|
| 10 |
|
| 11 |
+
with gr.Blocks() as imagegpt:
|
| 12 |
+
gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/ImageGPT-4XL' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
with gr.Blocks() as imageengine4k:
|
| 15 |
+
gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/DALLE-4K' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
with gr.Blocks() as imageengine2k:
|
| 18 |
+
gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/DALLE-2K' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
|
|
|
|
| 19 |
|
| 20 |
+
with gr.Blocks() as mediadownloader:
|
| 21 |
+
gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/All-In-One-Downloader' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
with gr.Blocks() as photofakes:
|
| 24 |
+
gr.HTML("<iframe src='https://huggingface.co/spaces/prithivMLmods/Face-Swap-Roop' width='100%' height='1000px' style='border-radius: 8px;'></iframe>")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# Assemble the components into a single Gradio interface
|
| 27 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="ChatGPT-Omni") as demo:
|
| 28 |
+
gr.Markdown("# ChatGPT-Omni")
|
| 29 |
+
gr.TabbedInterface(
|
| 30 |
+
[chatbot, imagegpt, imageengine4k, imageengine2k, mediadownloader, photofakes],
|
| 31 |
+
['ChatBot', 'ImageGPT', 'Image Engine 4K', 'Image Engine 2K', 'Media Downloader', 'PhotoFakes']
|
| 32 |
+
)
|
| 33 |
|
| 34 |
+
# Launch the demo
|
| 35 |
+
demo.queue().launch(debug=True)
|
| 36 |
|
| 37 |
+
# Run the main function
|
| 38 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|