Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,71 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
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 |
# Launch the Gradio app
|
52 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Initialize pipelines for text generation and speech recognition
|
5 |
+
text_generation_pipeline = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.2")
|
6 |
+
speech_recognition_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-large-v3-turbo")
|
7 |
+
|
8 |
+
# Function to transcribe audio using the Whisper pipeline
|
9 |
+
def transcribe_audio(audio_file):
|
10 |
+
try:
|
11 |
+
# Use the Whisper pipeline for automatic speech recognition
|
12 |
+
transcription = speech_recognition_pipeline(audio_file)
|
13 |
+
return transcription.get("text", "Transcription not available.")
|
14 |
+
except Exception as e:
|
15 |
+
return f"Error in transcription: {e}"
|
16 |
+
|
17 |
+
# Function to generate Mermaid.js code using the Mistral pipeline
|
18 |
+
def generate_mermaid_code(prompt):
|
19 |
+
try:
|
20 |
+
# Use the text-generation pipeline to generate Mermaid.js code
|
21 |
+
result = text_generation_pipeline(
|
22 |
+
prompt,
|
23 |
+
max_length=256,
|
24 |
+
temperature=0.7,
|
25 |
+
num_return_sequences=1
|
26 |
+
)
|
27 |
+
return result[0]["generated_text"].strip() if result else "No Mermaid.js code generated."
|
28 |
+
except Exception as e:
|
29 |
+
return f"Error in Mermaid.js generation: {e}"
|
30 |
+
|
31 |
+
# Function to process input (text, audio, or both)
|
32 |
+
def process_input(input_type, text_input, audio_input):
|
33 |
+
try:
|
34 |
+
if input_type == "Audio" and audio_input:
|
35 |
+
transcription = transcribe_audio(audio_input)
|
36 |
+
return generate_mermaid_code(transcription)
|
37 |
+
|
38 |
+
elif input_type == "Text" and text_input:
|
39 |
+
return generate_mermaid_code(text_input)
|
40 |
+
|
41 |
+
elif input_type == "Text and Audio" and text_input and audio_input:
|
42 |
+
transcription = transcribe_audio(audio_input)
|
43 |
+
combined_input = f"{text_input} and {transcription}"
|
44 |
+
return generate_mermaid_code(combined_input)
|
45 |
+
|
46 |
+
else:
|
47 |
+
return "Please provide valid input."
|
48 |
+
except Exception as e:
|
49 |
+
return f"Error: {e}"
|
50 |
+
|
51 |
+
# Set up the Gradio interface
|
52 |
+
iface = gr.Interface(
|
53 |
+
fn=process_input,
|
54 |
+
inputs=[
|
55 |
+
gr.Radio(["Text", "Audio", "Text and Audio"], label="Input Type", value="Text"),
|
56 |
+
gr.Textbox(lines=10, label="Text Input", placeholder="Enter task flow description here..."),
|
57 |
+
gr.Audio(type="filepath", label="Audio Input"),
|
58 |
+
],
|
59 |
+
outputs=[
|
60 |
+
gr.Textbox(lines=20, label="Generated Mermaid.js Code"),
|
61 |
+
],
|
62 |
+
title="Mermaid.js Generator",
|
63 |
+
description=(
|
64 |
+
"Provide text, audio, or both."
|
65 |
+
"Mermaid.js code will be generated for text or audio input, or their combination."
|
66 |
+
),
|
67 |
+
)
|
68 |
|
69 |
# Launch the Gradio app
|
70 |
+
if __name__ == "__main__":
|
71 |
+
iface.launch()
|