Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import speech_recognition as sr | |
| import soundfile as sf | |
| import cv2 | |
| from transformers import pipeline | |
| # Initialize Speech Recognition | |
| recognizer = sr.Recognizer() | |
| # Initialize Image Generation | |
| generator = pipeline('image-generation', model='CompVis/stable-diffusion-v1-4') | |
| # Function to recognize speech | |
| def recognize_speech(): | |
| with sr.Microphone() as source: | |
| print('Say something...') | |
| audio = recognizer.listen(source) | |
| try: | |
| text = recognizer.recognize_google(audio) | |
| return 'You said: ' + text | |
| except sr.UnknownValueError: | |
| return 'Google Speech Recognition could not understand audio' | |
| except sr.RequestError as e: | |
| return 'Could not request results; {0}'.format(e) | |
| # Function to recognize image | |
| def recognize_image(image): | |
| # Process image using OpenCV/TensorFlow | |
| return "Image recognized (not implemented)" | |
| # Function to generate image | |
| def generate_image(prompt): | |
| images = generator(prompt) | |
| return images[0] | |
| # Set up the Gradio interface | |
| def main_interface(): | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Mistral 0.2 Dolphin Interface") | |
| with gr.Tab("Recognize Speech"): | |
| speech_output = gr.Textbox(label="Recognized Speech") | |
| speech_button = gr.Button("Start Speaking") | |
| speech_button.click(fn=recognize_speech, outputs=speech_output) | |
| with gr.Tab("Recognize Image"): | |
| image_input = gr.Image(type="pil", label="Upload Image") | |
| image_output = gr.Textbox(label="Image Info") | |
| image_button = gr.Button("Recognize Image") | |
| image_button.click(fn=recognize_image, inputs=image_input, outputs=image_output) | |
| with gr.Tab("Generate Image"): | |
| prompt_input = gr.Textbox(label="Prompt") | |
| image_output = gr.Image(type="pil", label="Generated Image") | |
| image_button = gr.Button("Generate Image") | |
| image_button.click(fn=generate_image, inputs=prompt_input, outputs=image_output) | |
| return demo | |
| if __name__ == "__main__": | |
| main_interface().launch() | |