Bagda commited on
Commit
cbc7e45
·
verified ·
1 Parent(s): 43806cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -24
app.py CHANGED
@@ -1,31 +1,20 @@
1
  import gradio as gr
2
- from transformers import AutoProcessor, BarkModel
3
- import scipy.io.wavfile
4
- import numpy as np
5
 
6
- # Model और Processor लोड करें
7
- processor = AutoProcessor.from_pretrained("suno/bark")
8
- model = BarkModel.from_pretrained("suno/bark")
9
- model.to("cuda") # अगर GPU उपलब्ध है
10
 
11
- def generate_speech(text):
12
- inputs = processor(text, voice_preset="v2/hi_speaker_1") # हिंदी के लिए
13
- audio_array = model.generate(**inputs)
14
- audio_array = audio_array.cpu().numpy().squeeze()
15
- sample_rate = model.generation_config.sample_rate
16
- scipy.io.wavfile.write("output.wav", rate=sample_rate, data=audio_array)
17
- return "output.wav"
18
 
19
  with gr.Blocks() as demo:
20
- gr.Markdown("## Suno Bark Text-to-Speech")
21
- text_input = gr.Textbox(label="टेक्स्ट इनपुट करें")
22
- audio_output = gr.Audio(label="ऑडियो आउटपुट")
23
- generate_button = gr.Button("Generate Speech")
24
- generate_button.click(
25
- fn=generate_speech,
26
- inputs=text_input,
27
- outputs=audio_output
28
- )
29
 
30
  demo.launch()
31
-
 
1
  import gradio as gr
2
+ from transformers import pipeline
 
 
3
 
4
+ # AI मॉडल लोड करें (यहां text-generation के लिए)
5
+ model = pipeline("text-generation", model="gpt2")
 
 
6
 
7
+ def respond(message, chat_history):
8
+ # AI मॉडल से रिस्पॉन्स लें
9
+ response = model(message, max_length=50)[0]["generated_text"]
10
+ chat_history.append({"role": "user", "content": message})
11
+ chat_history.append({"role": "assistant", "content": response})
12
+ return "", chat_history
 
13
 
14
  with gr.Blocks() as demo:
15
+ chatbot = gr.Chatbot(type="messages")
16
+ msg = gr.Textbox(label="Type your message")
17
+ clear = gr.ClearButton([msg, chatbot])
18
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
 
 
 
 
 
19
 
20
  demo.launch()