File size: 1,462 Bytes
d52ffdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adef3c4
2a81121
d52ffdf
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import whisper
from groq import Groq
from diffusers import StableDiffusionPipeline
import gradio as gr
import torch

# Load Whisper model
whisper_model = whisper.load_model("base")

GROQ_API_KEY="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"
client=Groq(api_key=GROQ_API_KEY)

# Load Stable Diffusion pipeline
device = "cuda" if torch.cuda.is_available() else "cpu"

stable_diffusion_model = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5"
).to(device)

# Function to handle voice-to-image pipeline
def voice_to_image(audio):
    # Step 1: Transcribe audio to text using Whisper
    transcription = whisper_model.transcribe(audio)
    input_text = transcription["text"]

    # Step 2: Query LLM using Groq API
    chat_completion = client.chat.completions.create(
        messages=[
            {"role": "user", "content": input_text},
        ],
        model="llama3-8b-8192",
        stream=False,
    )
    response_text = chat_completion.choices[0].message.content

    # Step 3: Generate image using Stable Diffusion
    image = stable_diffusion_model(response_text).images[0]

    return image

# Gradio Interface
interface = gr.Interface(
    fn=voice_to_image,
    inputs=gr.Audio(type="filepath"),
    outputs="image",
    title="Voice-to-Image Generator",
    description="Transcribe voice input into an image using Whisper, Groq LLM, and Stable Diffusion."
)

# Launch Gradio app
interface.launch()