import spaces import gradio as gr from transformers import pipeline import os import torch # Set max_split_size_mb # os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:50' title = """# 🙋🏻‍♂️Welcome to🌟Tonic's Nexus🐦‍⬛Raven""" description = """You can build with this endpoint using Nexus Raven. The demo is still a work in progress but we hope to add some endpoints for commonly used functions such as intention mappers and audiobook processing. You can also use Nexus🐦‍⬛Raven on your laptop & by cloning this space. 🧬🔬🔍 Simply click here: Duplicate Space Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's🛠️community on 👻Discord: [Discord](https://discord.gg/GWpVpekp) On 🤗Huggingface: [TeamTonic](https://huggingface.co./TeamTonic) & [MultiTransformer](https://huggingface.co./MultiTransformer) On 🌐Github: [Polytonic](https://github.com/tonic-ai) & contribute to 🌟 [PolyGPT](https://github.com/tonic-ai/polygpt-alpha) """ raven_pipeline = pipeline( "text-generation", model="Nexusflow/NexusRaven-V2-13B", torch_dtype="auto", device_map="auto", ) @spaces.GPU def process_text(input_text: str) -> str: prompt = f"User Query: {input_text}" result = raven_pipeline(prompt, max_new_tokens=2048, return_full_text=False, do_sample=False, temperature=0.001)[0]["generated_text"] torch.cuda.empty_cache() return result def create_interface(): with gr.Blocks() as app: gr.Markdown(title) gr.Markdown(description) with gr.Row(): input_text = gr.Textbox(label="Input Text") submit_button = gr.Button("Submit") output_text = gr.Textbox(label="Nexus🐦‍⬛Raven") submit_button.click(converter.process_text, inputs=input_text, outputs=output_text) return app def main(): with gr.Blocks() as demo: gr.Markdown(title) gr.Markdown(description) with gr.Row(): input_text = gr.Textbox(label="Input Text", placeholder="Enter your text here...") submit_button = gr.Button("Submit") output_text = gr.Textbox(label="Nexus🐦‍⬛Raven", placeholder="Generated text will appear here...") submit_button.click(process_text, inputs=input_text, outputs=output_text) demo.launch() if __name__ == "__main__": main()