Shabbir-Anjum commited on
Commit
ec7471c
·
verified ·
1 Parent(s): 98ec984

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -29
app.py CHANGED
@@ -1,40 +1,32 @@
1
  import streamlit as st
2
- from diffusers import DiffusionPipeline
3
 
4
- # Load the Diffusion pipeline
5
- @st.cache_data(allow_output_mutation=True)
6
- def load_diffusion_pipeline():
7
- try:
8
- pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-3-medium")
9
- return pipeline
10
- except Exception as e:
11
- st.error(f"Error loading model: {e}")
12
 
13
- def generate_response(prompt_text, pipeline):
14
- try:
15
- response = pipeline(prompt_text, top_p=0.9, max_length=100)[0]['generated_text']
16
- return response
17
- except Exception as e:
18
- st.error(f"Error generating response: {e}")
19
 
20
  def main():
21
- st.title('Hugging Face Diffusion Model')
22
 
23
- # Load the model
24
- pipeline = load_diffusion_pipeline()
 
25
 
26
- # Text input for the prompt
27
- prompt_text = st.text_area("Enter your prompt here:", height=200)
 
28
 
29
- # Button to generate prompt
30
- if st.button("Generate"):
31
- if prompt_text:
32
- with st.spinner('Generating...'):
33
- generated_text = generate_response(prompt_text, pipeline)
34
- st.success('Generation complete!')
35
- st.text_area('Generated Text:', value=generated_text, height=400)
36
- else:
37
- st.warning('Please enter a prompt.')
38
 
39
  if __name__ == '__main__':
40
  main()
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
 
4
+ # Load the audio classification pipeline
5
+ audio_classification_pipeline = pipeline("audio-classification", model="MIT/ast-finetuned-audioset-10-10-0.4593")
 
 
 
 
 
 
6
 
7
+ def classify_audio(audio_file):
8
+ # Perform audio classification
9
+ results = audio_classification_pipeline(audio=audio_file)
10
+ return results
 
 
11
 
12
  def main():
13
+ st.title('Hugging Face Audio Classification')
14
 
15
+ # File uploader for audio file
16
+ st.subheader('Upload Audio File:')
17
+ audio_file = st.file_uploader("Choose a WAV file", type=["wav"])
18
 
19
+ # Check if audio file is uploaded
20
+ if audio_file is not None:
21
+ st.audio(audio_file, format='audio/wav')
22
 
23
+ # Button to classify audio
24
+ if st.button('Classify'):
25
+ with st.spinner('Classifying...'):
26
+ # Perform classification
27
+ results = classify_audio(audio_file)
28
+ st.success('Classification complete!')
29
+ st.write("Prediction:", results)
 
 
30
 
31
  if __name__ == '__main__':
32
  main()