Spaces:
Runtime error
Runtime error
Commit ·
75a2e17
1
Parent(s): dd1c601
Add application and requirements files
Browse files- app.py +60 -0
- requirements.txt +11 -0
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import speech_recognition as sr
|
| 3 |
+
import cv2
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
# Initialize Speech Recognition
|
| 7 |
+
recognizer = sr.Recognizer()
|
| 8 |
+
|
| 9 |
+
# Initialize Image Generation
|
| 10 |
+
generator = pipeline('image-generation', model='CompVis/stable-diffusion-v1-4')
|
| 11 |
+
|
| 12 |
+
# Function to recognize speech
|
| 13 |
+
def recognize_speech():
|
| 14 |
+
with sr.Microphone() as source:
|
| 15 |
+
print('Say something...')
|
| 16 |
+
audio = recognizer.listen(source)
|
| 17 |
+
try:
|
| 18 |
+
text = recognizer.recognize_google(audio)
|
| 19 |
+
return 'You said: ' + text
|
| 20 |
+
except sr.UnknownValueError:
|
| 21 |
+
return 'Google Speech Recognition could not understand audio'
|
| 22 |
+
except sr.RequestError as e:
|
| 23 |
+
return 'Could not request results; {0}'.format(e)
|
| 24 |
+
|
| 25 |
+
# Function to recognize image
|
| 26 |
+
def recognize_image(image):
|
| 27 |
+
# Process image using OpenCV/TensorFlow
|
| 28 |
+
return "Image recognized (not implemented)"
|
| 29 |
+
|
| 30 |
+
# Function to generate image
|
| 31 |
+
def generate_image(prompt):
|
| 32 |
+
images = generator(prompt)
|
| 33 |
+
return images[0]
|
| 34 |
+
|
| 35 |
+
# Set up the Gradio interface
|
| 36 |
+
def main_interface():
|
| 37 |
+
with gr.Blocks() as demo:
|
| 38 |
+
gr.Markdown("# Mistral 0.2 Dolphin Interface")
|
| 39 |
+
|
| 40 |
+
with gr.Tab("Recognize Speech"):
|
| 41 |
+
speech_output = gr.Textbox(label="Recognized Speech")
|
| 42 |
+
speech_button = gr.Button("Start Speaking")
|
| 43 |
+
speech_button.click(fn=recognize_speech, outputs=speech_output)
|
| 44 |
+
|
| 45 |
+
with gr.Tab("Recognize Image"):
|
| 46 |
+
image_input = gr.Image(type="pil", label="Upload Image")
|
| 47 |
+
image_output = gr.Textbox(label="Image Info")
|
| 48 |
+
image_button = gr.Button("Recognize Image")
|
| 49 |
+
image_button.click(fn=recognize_image, inputs=image_input, outputs=image_output)
|
| 50 |
+
|
| 51 |
+
with gr.Tab("Generate Image"):
|
| 52 |
+
prompt_input = gr.Textbox(label="Prompt")
|
| 53 |
+
image_output = gr.Image(type="pil", label="Generated Image")
|
| 54 |
+
image_button = gr.Button("Generate Image")
|
| 55 |
+
image_button.click(fn=generate_image, inputs=prompt_input, outputs=image_output)
|
| 56 |
+
|
| 57 |
+
return demo
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
main_interface().launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
SpeechRecognition
|
| 2 |
+
pyaudio
|
| 3 |
+
opencv-python-headless
|
| 4 |
+
tensorflow
|
| 5 |
+
torch
|
| 6 |
+
torchvision
|
| 7 |
+
torchaudio
|
| 8 |
+
diffusers
|
| 9 |
+
transformers
|
| 10 |
+
pyyaml
|
| 11 |
+
gradio
|