Futuresony commited on
Commit
76004f6
·
verified ·
1 Parent(s): 045101e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -1,9 +1,7 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
  client = InferenceClient(model="Futuresony/future_ai_12_10_2024.gguf")
8
 
9
 
@@ -26,7 +24,6 @@ def respond(
26
  messages.append({"role": "user", "content": message})
27
 
28
  response = ""
29
-
30
  for message in client.chat_completion(
31
  messages,
32
  max_tokens=max_tokens,
@@ -35,12 +32,11 @@ def respond(
35
  top_p=top_p,
36
  ):
37
  token = message.choices[0].delta.content
38
-
39
  response += token
40
  yield response
41
 
42
 
43
- # JavaScript for speech recognition
44
  speech_recognition_js = """
45
  <script>
46
  let micButton = document.getElementById('mic_button');
@@ -58,11 +54,11 @@ speech_recognition_js = """
58
  };
59
 
60
  recognition.onspeechend = function() {
61
- recognition.stop(); // Stop listening after 2 seconds of silence
62
  };
63
 
64
  micButton.onclick = function() {
65
- recognition.start(); // Start listening when mic button is clicked
66
  };
67
  } else {
68
  micButton.onclick = function() {
@@ -72,7 +68,7 @@ speech_recognition_js = """
72
  </script>
73
  """
74
 
75
- # Gradio Chat Interface
76
  demo = gr.ChatInterface(
77
  fn=respond,
78
  additional_inputs=[
@@ -89,7 +85,7 @@ demo = gr.ChatInterface(
89
  ],
90
  )
91
 
92
- # Add mic button to the interface
93
  with gr.Blocks() as ui:
94
  with gr.Row():
95
  gr.HTML(
@@ -111,12 +107,12 @@ with gr.Blocks() as ui:
111
  </style>
112
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined">
113
  <div style="display: flex; align-items: center;">
114
- <button id="mic_button">🎤</button>
115
  <input id="user_input" type="text" placeholder="Type your message here..." />
116
  </div>
117
  """
118
  )
119
- gr.HTML(speech_recognition_js) # Inject JavaScript for mic button
120
 
121
  demo.launch()
122
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # Initialize Hugging Face Inference Client
 
 
5
  client = InferenceClient(model="Futuresony/future_ai_12_10_2024.gguf")
6
 
7
 
 
24
  messages.append({"role": "user", "content": message})
25
 
26
  response = ""
 
27
  for message in client.chat_completion(
28
  messages,
29
  max_tokens=max_tokens,
 
32
  top_p=top_p,
33
  ):
34
  token = message.choices[0].delta.content
 
35
  response += token
36
  yield response
37
 
38
 
39
+ # JavaScript for speech-to-text functionality
40
  speech_recognition_js = """
41
  <script>
42
  let micButton = document.getElementById('mic_button');
 
54
  };
55
 
56
  recognition.onspeechend = function() {
57
+ recognition.stop();
58
  };
59
 
60
  micButton.onclick = function() {
61
+ recognition.start();
62
  };
63
  } else {
64
  micButton.onclick = function() {
 
68
  </script>
69
  """
70
 
71
+ # Chat Interface with Additional Inputs
72
  demo = gr.ChatInterface(
73
  fn=respond,
74
  additional_inputs=[
 
85
  ],
86
  )
87
 
88
+ # Add Mic Button to the Interface
89
  with gr.Blocks() as ui:
90
  with gr.Row():
91
  gr.HTML(
 
107
  </style>
108
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined">
109
  <div style="display: flex; align-items: center;">
110
+ <button id="mic_button" title="Click to speak">🎤</button>
111
  <input id="user_input" type="text" placeholder="Type your message here..." />
112
  </div>
113
  """
114
  )
115
+ gr.HTML(speech_recognition_js) # Include JS for mic button functionality
116
 
117
  demo.launch()
118