Spaces:
Runtime error
Runtime error
Rename app.py(bad) to app.py
Browse files- app.py +45 -0
- app.py(bad) +0 -50
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from asr import transcribe_audio # Your ASR function
|
| 3 |
+
from lid import detect_language # Your Language Identification function
|
| 4 |
+
from tts import text_to_speech # Your TTS function
|
| 5 |
+
from transformers import pipeline
|
| 6 |
+
|
| 7 |
+
# Load the text generation model (adjust this based on your model type)
|
| 8 |
+
text_generator = pipeline("text-generation", model="Futuresony/12_10_2024.gguf")
|
| 9 |
+
|
| 10 |
+
# Function to process input
|
| 11 |
+
def process_input(input_text=None, audio=None):
|
| 12 |
+
if audio: # If audio is provided, convert it to text
|
| 13 |
+
input_text = transcribe_audio(audio)
|
| 14 |
+
|
| 15 |
+
if not input_text:
|
| 16 |
+
return "No input provided", None
|
| 17 |
+
|
| 18 |
+
# Detect language
|
| 19 |
+
lang = detect_language(input_text)
|
| 20 |
+
|
| 21 |
+
# Generate text using the model
|
| 22 |
+
output_text = text_generator(input_text, max_length=100, do_sample=True)[0]['generated_text']
|
| 23 |
+
|
| 24 |
+
# Convert output text to speech
|
| 25 |
+
output_audio = text_to_speech(output_text, lang)
|
| 26 |
+
|
| 27 |
+
return output_text, output_audio
|
| 28 |
+
|
| 29 |
+
# Create Gradio interface
|
| 30 |
+
interface = gr.Interface(
|
| 31 |
+
fn=process_input,
|
| 32 |
+
inputs=[
|
| 33 |
+
gr.Textbox(label="Enter Text", placeholder="Type here..."),
|
| 34 |
+
gr.Audio(source="microphone", type="filepath", label="Record Audio")
|
| 35 |
+
],
|
| 36 |
+
outputs=[
|
| 37 |
+
gr.Textbox(label="Generated Text"),
|
| 38 |
+
gr.Audio(label="Generated Speech")
|
| 39 |
+
],
|
| 40 |
+
title="Speech-to-Text AI Chat",
|
| 41 |
+
description="Input text or record audio, and the AI will respond with generated text and speech."
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Run the demo
|
| 45 |
+
interface.launch()
|
app.py(bad)
DELETED
|
@@ -1,50 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import subprocess
|
| 3 |
-
import os
|
| 4 |
-
from huggingface_hub import InferenceClient
|
| 5 |
-
|
| 6 |
-
# Initialize Chatbot Model (Futuresony.gguf)
|
| 7 |
-
chat_client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf") # Change if needed
|
| 8 |
-
|
| 9 |
-
def asr_chat_tts(audio):
|
| 10 |
-
"""
|
| 11 |
-
1. Convert Speech to Text using asr.py
|
| 12 |
-
2. Process text through Chat Model (Futuresony.gguf)
|
| 13 |
-
3. Convert response to Speech using tts.py
|
| 14 |
-
"""
|
| 15 |
-
# Step 1: Run ASR (Speech-to-Text)
|
| 16 |
-
asr_output = subprocess.run(["python3", "asr.py", audio], capture_output=True, text=True)
|
| 17 |
-
transcription = asr_output.stdout.strip()
|
| 18 |
-
|
| 19 |
-
# Step 2: Process text through the chat model
|
| 20 |
-
messages = [{"role": "system", "content": "You are a helpful AI assistant."}]
|
| 21 |
-
messages.append({"role": "user", "content": transcription})
|
| 22 |
-
|
| 23 |
-
response = ""
|
| 24 |
-
for msg in chat_client.chat_completion(messages, max_tokens=512, stream=True):
|
| 25 |
-
token = msg.choices[0].delta.content
|
| 26 |
-
response += token
|
| 27 |
-
|
| 28 |
-
# Step 3: Run TTS (Text-to-Speech)
|
| 29 |
-
tts_output_file = "generated_speech.wav"
|
| 30 |
-
subprocess.run(["python3", "tts.py", response, tts_output_file])
|
| 31 |
-
|
| 32 |
-
return transcription, response, tts_output_file
|
| 33 |
-
|
| 34 |
-
# Gradio Interface
|
| 35 |
-
with gr.Blocks() as demo:
|
| 36 |
-
gr.Markdown("<h2 style='text-align: center;'>ASR β Chatbot β TTS</h2>")
|
| 37 |
-
|
| 38 |
-
with gr.Row():
|
| 39 |
-
audio_input = gr.Audio(source="microphone", type="filepath", label="π€ Speak Here")
|
| 40 |
-
text_transcription = gr.Textbox(label="π Transcription", interactive=False)
|
| 41 |
-
text_response = gr.Textbox(label="π€ Chatbot Response", interactive=False)
|
| 42 |
-
audio_output = gr.Audio(label="π Generated Speech")
|
| 43 |
-
|
| 44 |
-
submit_button = gr.Button("Process Speech π")
|
| 45 |
-
|
| 46 |
-
submit_button.click(fn=asr_chat_tts, inputs=[audio_input], outputs=[text_transcription, text_response, audio_output])
|
| 47 |
-
|
| 48 |
-
# Run the App
|
| 49 |
-
if __name__ == "__main__":
|
| 50 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|