AIVoiceModels / Llama.py
muhammedAdnan3's picture
Create Llama.py
870a44e verified
import pyttsx3
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
# Load pre-trained model and tokenizer from Hugging Face
model_name = "decapoda-research/llama-7b-hf" # Placeholder, replace with actual model if available
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Initialize text-to-speech engine
tts_engine = pyttsx3.init()
def generate_text(prompt):
# Use the model to generate text based on the prompt
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(inputs["input_ids"], max_length=50)
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return generated_text
def text_to_speech(text):
# Use the TTS engine to convert text to speech
tts_engine.say(text)
tts_engine.runAndWait()
def main():
prompt = "Once upon a time" # Replace with your desired prompt
generated_text = generate_text(prompt)
print(f"Generated Text: {generated_text}")
text_to_speech(generated_text)
if __name__ == "__main__":
main()