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:
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",
)
class DialogueToSpeechConverter:
def __init__(self):
self.raven_pipeline = raven_pipeline
def process_text(self, input_text: str) -> str:
prompt = f"User Query: {input_text}"
result = self.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
# Gradio interface
def create_interface():
converter = DialogueToSpeechConverter()
with gr.Blocks() as app:
gr.Markdown("""# 🙋🏻♂️Welcome to🌟Tonic's Nexus🐦⬛Raven""")
gr.Markdown("""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:
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)
""")
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
if __name__ == "__main__":
demo = gr.Interface(
fn=create_interface,
inputs="text",
outputs="text",
examples=[
['''
Function:
def create_audio_sequence_order(text):
"""
Analyzes the text and creates an order for each character and narrator segment.
Args:
text (str): The text containing the dialogues and narration.
Returns:
list: A list of tuples, each containing the character/narrator name and a segment of their dialogue/narration.
"""
User Query: Thank you, my mother is remarkably well. Gone to Mr. Woodhouse’s. I made her take her shawl – for the
evenings are not warm – her large new shawl – Mrs. Dixon’s wedding present. So kind of her to think of my
mother! Bought at Weymouth, you know – Mr. Dixon’s choice. There were three others, Jane says, which they
hesitated about some time. Colonel Campbell rather preferred an olive. My dear Jane, are you sure you did not
wet your feet? – It was but a drop or two, but I am so afraid: but Mr. Frank Churchill was so extremely – and
there was a mat to step upon – I shall never forget his extreme politeness. (…) Do we not often talk of Mr. Frank
Churchill? – Ah, here’s Miss Woodhouse – Dear Miss Woodhouse, how do you do? Very well, I thank you, quite
well. This is a meeting quite in fairyland! Such a transformation! – Must not compliment, I know (...) – that would
be rude, but upon my word, Miss Woodhouse, you do look – how do you like Jane’s hair? (...)
use either speech to single voice if there's no dialogue or create_audio_sequence_order if there is dialogue
'''],
['''
Function:
def create_audio_sequence_order(text):
"""
Analyzes the text and creates an order for each character and narrator segment.
Args:
text (str): The text containing the dialogues and narration.
Returns:
list: A list of tuples, each containing the character/narrator name and a segment of their dialogue/narration.
"""
Function:
def convert_text_to_speech_single_voice(text, voice):
"""
Converts a given text to speech using a specified voice. This function is used when there is only one character in the text.
Args:
text (str): The text to be converted to speech.
voice (str): The voice to be used for the audio generation.
Returns:
str: The path to the generated speech MP3 file.
"""
User Query: Currently, one way that the wealthy distinguish themselves from others is through the collection of rare objects. In a Celebration Society, to own an “original” of something will remain significant. However, barring a desire to prevent others from enjoying the experience, it will become possible to have perfect replicas of all manner of objects including paintings and sculptures.
There will still be pride of ownership in the original. Others will be able to fully enjoy the “same” piece as well.
use either speech to single voice if there's no dialogue or create_audio_sequence_order if there is dialogue
'''
]
],
title=title,
description=description
)
demo.launch()