Spaces:
Runtime error
Runtime error
N.Achyuth Reddy
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Constants
|
5 |
TITLE = "AgriTure"
|
@@ -12,22 +17,25 @@ Hope this will be a Successful Project!!!
|
|
12 |
"""
|
13 |
MEMBERSHIP_PRICE_USD = 10.0
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
23 |
}
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
# Streamlit UI
|
33 |
st.title(TITLE)
|
@@ -44,10 +52,17 @@ for message in st.session_state.messages:
|
|
44 |
textinput = st.chat_input("Ask AgriTure anything...")
|
45 |
|
46 |
# Payment and Membership Subscription
|
47 |
-
if st.button("Subscribe with
|
48 |
-
|
49 |
-
|
50 |
-
st.write("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
# React to user input
|
53 |
if textinput:
|
@@ -63,5 +78,11 @@ if textinput:
|
|
63 |
with st.chat_message("assistant", avatar='🌿'):
|
64 |
st.markdown(response)
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
# Add assistant response to chat history
|
67 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
1 |
import streamlit as st
|
2 |
+
from coinbase_commerce.client import Client
|
3 |
+
from gtts import gTTS
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Initialize Coinbase Commerce client
|
7 |
+
client = Client(api_key='YOUR_API_KEY')
|
8 |
|
9 |
# Constants
|
10 |
TITLE = "AgriTure"
|
|
|
17 |
"""
|
18 |
MEMBERSHIP_PRICE_USD = 10.0
|
19 |
|
20 |
+
# Function to create a charge for membership
|
21 |
+
def create_membership_charge(currency):
|
22 |
+
charge_data = {
|
23 |
+
'name': 'Monthly Membership',
|
24 |
+
'description': 'Access to premium features for one month',
|
25 |
+
'local_price': {
|
26 |
+
'amount': MEMBERSHIP_PRICE_USD,
|
27 |
+
'currency': currency
|
28 |
+
},
|
29 |
+
'pricing_type': 'fixed_price'
|
30 |
}
|
31 |
+
charge = client.charge.create(**charge_data)
|
32 |
+
return charge
|
33 |
+
|
34 |
+
# Function to convert text to speech using gTTS
|
35 |
+
def text_to_speech(text, lang='en'):
|
36 |
+
tts = gTTS(text=text, lang=lang, slow=False)
|
37 |
+
tts.save("response.mp3")
|
38 |
+
return "response.mp3"
|
39 |
|
40 |
# Streamlit UI
|
41 |
st.title(TITLE)
|
|
|
52 |
textinput = st.chat_input("Ask AgriTure anything...")
|
53 |
|
54 |
# Payment and Membership Subscription
|
55 |
+
if st.button("Subscribe with Bitcoin"):
|
56 |
+
charge = create_membership_charge('BTC')
|
57 |
+
bitcoin_address = charge['addresses']['bitcoin']
|
58 |
+
st.write("Please send Bitcoin to the following address:", bitcoin_address)
|
59 |
+
st.write("Your membership will be activated once the payment is confirmed.")
|
60 |
+
|
61 |
+
if st.button("Subscribe with Litecoin"):
|
62 |
+
charge = create_membership_charge('LTC')
|
63 |
+
litecoin_address = charge['addresses']['litecoin']
|
64 |
+
st.write("Please send Litecoin to the following address:", litecoin_address)
|
65 |
+
st.write("Your membership will be activated once the payment is confirmed.")
|
66 |
|
67 |
# React to user input
|
68 |
if textinput:
|
|
|
78 |
with st.chat_message("assistant", avatar='🌿'):
|
79 |
st.markdown(response)
|
80 |
|
81 |
+
# Convert AI response to speech
|
82 |
+
speech_file = text_to_speech(response)
|
83 |
+
|
84 |
+
# Play the generated speech
|
85 |
+
st.audio(speech_file, format="audio/mp3")
|
86 |
+
|
87 |
# Add assistant response to chat history
|
88 |
st.session_state.messages.append({"role": "assistant", "content": response})
|