Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
-
import os
|
4 |
import requests
|
|
|
|
|
5 |
|
6 |
-
# Set up the Hugging Face API key
|
7 |
api_key = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
8 |
|
9 |
-
#
|
10 |
WHISPER_API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
11 |
|
12 |
# Set up headers for the Whisper API request
|
13 |
headers = {"Authorization": f"Bearer {api_key}"}
|
14 |
|
15 |
-
# Load the DeepSeek model using
|
16 |
-
|
17 |
|
18 |
-
# Function to query the Hugging Face Whisper model for audio transcription
|
19 |
def transcribe_audio(audio_file):
|
20 |
with open(audio_file, "rb") as f:
|
21 |
data = f.read()
|
@@ -25,14 +25,14 @@ def transcribe_audio(audio_file):
|
|
25 |
else:
|
26 |
return f"Error: {response.status_code}, {response.text}"
|
27 |
|
28 |
-
# Function to generate Mermaid.js code using DeepSeek
|
29 |
def generate_mermaid_code(prompt):
|
30 |
# Instruction included in the prompt to guide DeepSeek to generate valid MermaidJS code
|
31 |
deepseek_prompt = f"Generate a valid MermaidJS diagram code for the following: {prompt}"
|
32 |
|
33 |
-
#
|
34 |
-
response =
|
35 |
-
return response.strip()
|
36 |
|
37 |
# Function to process text, audio, or both inputs
|
38 |
def process_input(input_type, text_input, audio_input):
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
import requests
|
3 |
+
import os
|
4 |
+
from transformers import pipeline
|
5 |
|
6 |
+
# Set up the Hugging Face API key (ensure you've set this as an environment variable)
|
7 |
api_key = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
8 |
|
9 |
+
# API URL for Whisper (audio transcription)
|
10 |
WHISPER_API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
11 |
|
12 |
# Set up headers for the Whisper API request
|
13 |
headers = {"Authorization": f"Bearer {api_key}"}
|
14 |
|
15 |
+
# Load the DeepSeek model using Hugging Face's pipeline
|
16 |
+
pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1-Distill-Qwen-7B")
|
17 |
|
18 |
+
# Function to query the Hugging Face Whisper model for audio transcription
|
19 |
def transcribe_audio(audio_file):
|
20 |
with open(audio_file, "rb") as f:
|
21 |
data = f.read()
|
|
|
25 |
else:
|
26 |
return f"Error: {response.status_code}, {response.text}"
|
27 |
|
28 |
+
# Function to generate Mermaid.js code using the DeepSeek model (replaces Mistral API call)
|
29 |
def generate_mermaid_code(prompt):
|
30 |
# Instruction included in the prompt to guide DeepSeek to generate valid MermaidJS code
|
31 |
deepseek_prompt = f"Generate a valid MermaidJS diagram code for the following: {prompt}"
|
32 |
|
33 |
+
# Using the DeepSeek model pipeline for text generation
|
34 |
+
response = pipe([{"role": "user", "content": deepseek_prompt}])
|
35 |
+
return response[0]["generated_text"].strip()
|
36 |
|
37 |
# Function to process text, audio, or both inputs
|
38 |
def process_input(input_type, text_input, audio_input):
|