Shabbir-Anjum commited on
Commit
59f752a
1 Parent(s): d544fbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -41
app.py CHANGED
@@ -1,42 +1,36 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
- from pydub import AudioSegment
4
- import io
5
-
6
- # Load the audio classification pipeline
7
- audio_classification_pipeline = pipeline("audio-classification", model="MIT/ast-finetuned-audioset-10-10-0.4593")
8
-
9
- def convert_mp3_to_wav(audio_bytes):
10
- # Convert MP3 bytes to WAV format
11
- audio = AudioSegment.from_file(io.BytesIO(audio_bytes), format="mp3")
12
- wav_bytes = audio.export(format="wav").read()
13
- return wav_bytes
14
-
15
- def classify_audio(wav_bytes):
16
- # Perform audio classification
17
- results = audio_classification_pipeline(inputs=wav_bytes)
18
- return results
19
-
20
- def main():
21
- st.title('Hugging Face Audio Classification')
22
-
23
- # File uploader for audio file
24
- st.subheader('Upload Audio File:')
25
- audio_file = st.file_uploader("Choose an MP3 file", type=["mp3"])
26
-
27
- # Check if audio file is uploaded
28
- if audio_file is not None:
29
- st.audio(audio_file, format='audio/mp3')
30
-
31
- # Button to classify audio
32
- if st.button('Classify'):
33
- with st.spinner('Classifying...'):
34
- # Convert MP3 to WAV and classify
35
- wav_bytes = convert_mp3_to_wav(audio_file.read())
36
- results = classify_audio(wav_bytes)
37
- st.success('Classification complete!')
38
- st.write("Prediction:", results)
39
-
40
- if __name__ == '__main__':
41
- main()
42
-
 
1
  import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import requests
4
+
5
+ # Initialize the tokenizer and model
6
+ tokenizer = AutoTokenizer.from_pretrained("PawanKrd/CosmosRP-8k")
7
+ model = AutoModelForCausalLM.from_pretrained("PawanKrd/CosmosRP-8k")
8
+
9
+ st.title("CosmosRP-8k Roleplay Chatbot")
10
+
11
+ user_input = st.text_input("You:", "")
12
+
13
+ if st.button("Generate Response"):
14
+ if user_input:
15
+ # Define the endpoint and payload
16
+ endpoint_url = "https://api.pawan.krd/cosmosrp/v1/chat/completions"
17
+ headers = {
18
+ "Content-Type": "application/json"
19
+ }
20
+ data = {
21
+ "model": "cosmosrp",
22
+ "messages": [
23
+ {"role": "system", "content": "You are a roleplay assistant."},
24
+ {"role": "user", "content": user_input}
25
+ ]
26
+ }
27
+
28
+ # Make the request to the API
29
+ response = requests.post(endpoint_url, headers=headers, json=data)
30
+ result = response.json()
31
+
32
+ # Extract and display the response
33
+ generated_response = result['choices'][0]['message']['content']
34
+ st.text_area("CosmosRP-8k:", generated_response)
35
+ else:
36
+ st.warning("Please enter some text.")