genaibeauty commited on
Commit
3351f1c
·
verified ·
1 Parent(s): a4c2d51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
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 for Whisper
7
  api_key = os.getenv("HUGGINGFACEHUB_API_TOKEN")
8
 
9
- # Set up the API URL for Whisper
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 Gradio's load function from the registry
16
- demo = gr.load(name="deepseek-ai/DeepSeek-R1", src="transformers_gradio.registry")
17
 
18
- # Function to query the Hugging Face Whisper model for audio transcription (API call)
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-R1 model
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
- # Use the loaded model `demo` to generate the MermaidJS code
34
- response = demo(deepseek_prompt)
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):