pyresearch commited on
Commit
4cfe952
·
verified ·
1 Parent(s): 25f4eeb

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -20,7 +20,7 @@ MODEL_VERSION_ID_DALLE = 'dc9dcb6ee67543cebc0b9a025861b868'
20
 
21
 
22
  # Streamlit app
23
- # Set your Clarifai credentials for Text-to-Speech (TTS)
24
  PAT_TTS = 'bfdeb4029ef54d23a2e608b0aa4c00e4'
25
  USER_ID_TTS = 'openai'
26
  APP_ID_TTS = 'tts'
@@ -28,7 +28,7 @@ MODEL_ID_TTS = 'openai-tts-1'
28
  MODEL_VERSION_ID_TTS = 'fff6ce1fd487457da95b79241ac6f02d'
29
 
30
 
31
- # Set up gRPC channel for Text-to-Speech (TTS)
32
  channel_tts = ClarifaiChannel.get_grpc_channel()
33
  stub_tts = service_pb2_grpc.V2Stub(channel_tts)
34
  metadata_tts = (('authorization', 'Key ' + PAT_TTS),)
@@ -40,7 +40,7 @@ st.title("NewsGuardian")
40
 
41
  # Inserting logo
42
  st.image("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTdA-MJ_SUCRgLs1prqudpMdaX4x-x10Zqlwp7cpzXWCMM9xjBAJYWdJsDlLoHBqNpj8qs&usqp=CAU")
43
- # Function to get gRPC channel for Text-to-Speech (TTS)
44
  def get_tts_channel():
45
  channel_tts = ClarifaiChannel.get_grpc_channel()
46
  return channel_tts, channel_tts.metadata
@@ -48,7 +48,7 @@ def get_tts_channel():
48
 
49
 
50
  # User input
51
- model_type = st.selectbox("Select Model", ["NewsGuardian model"])
52
  raw_text = st.text_area("This news is real or fake?")
53
  image_upload = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
54
 
@@ -116,7 +116,7 @@ if st.button("NewsGuardian News Result"):
116
  tts_output = tts_response.outputs[0].data
117
  st.audio(tts_output.audio.base64, format='audio/wav')
118
  else:
119
- st.error(f"Text-to-Speech (TTS) API request failed: {tts_response.status.description}")
120
 
121
  elif model_type == "DALL-E":
122
  # Set up gRPC channel for DALL-E
@@ -154,14 +154,14 @@ if st.button("NewsGuardian News Result"):
154
  elif output_dalle.HasField("text"):
155
  st.text(output_dalle.text.raw)
156
 
157
- elif model_type == "Text-to-Speech (TTS)":
158
- # Set up gRPC channel for Text-to-Speech (TTS)
159
  channel_tts = ClarifaiChannel.get_grpc_channel()
160
  stub_tts = service_pb2_grpc.V2Stub(channel_tts)
161
  metadata_tts = (('authorization', 'Key ' + PAT_TTS),)
162
  userDataObject_tts = resources_pb2.UserAppIDSet(user_id=USER_ID_TTS, app_id=APP_ID_TTS)
163
 
164
- # Prepare the request for Text-to-Speech (TTS)
165
  input_data_tts = resources_pb2.Data()
166
 
167
  if raw_text:
@@ -177,14 +177,14 @@ if st.button("NewsGuardian News Result"):
177
  metadata=metadata_tts
178
  )
179
 
180
- # Check if the request was successful for Text-to-Speech (TTS)
181
  if post_model_outputs_response_tts.status.code != status_code_pb2.SUCCESS:
182
- st.error(f"Text-to-Speech (TTS) API request failed: {post_model_outputs_response_tts.status.description}")
183
  else:
184
- # Get the output for Text-to-Speech (TTS)
185
  output_tts = post_model_outputs_response_tts.outputs[0].data
186
 
187
- # Display the result for Text-to-Speech (TTS)
188
  if output_tts.HasField("text"):
189
  st.text(output_tts.text.raw)
190
 
 
20
 
21
 
22
  # Streamlit app
23
+ # Set your Clarifai credentials for NewsGuardian model
24
  PAT_TTS = 'bfdeb4029ef54d23a2e608b0aa4c00e4'
25
  USER_ID_TTS = 'openai'
26
  APP_ID_TTS = 'tts'
 
28
  MODEL_VERSION_ID_TTS = 'fff6ce1fd487457da95b79241ac6f02d'
29
 
30
 
31
+ # Set up gRPC channel for NewsGuardian model
32
  channel_tts = ClarifaiChannel.get_grpc_channel()
33
  stub_tts = service_pb2_grpc.V2Stub(channel_tts)
34
  metadata_tts = (('authorization', 'Key ' + PAT_TTS),)
 
40
 
41
  # Inserting logo
42
  st.image("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTdA-MJ_SUCRgLs1prqudpMdaX4x-x10Zqlwp7cpzXWCMM9xjBAJYWdJsDlLoHBqNpj8qs&usqp=CAU")
43
+ # Function to get gRPC channel for NewsGuardian model
44
  def get_tts_channel():
45
  channel_tts = ClarifaiChannel.get_grpc_channel()
46
  return channel_tts, channel_tts.metadata
 
48
 
49
 
50
  # User input
51
+ model_type = st.selectbox("Select Model", ["NewsGuardian model","NewsGuardian model"])
52
  raw_text = st.text_area("This news is real or fake?")
53
  image_upload = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
54
 
 
116
  tts_output = tts_response.outputs[0].data
117
  st.audio(tts_output.audio.base64, format='audio/wav')
118
  else:
119
+ st.error(f"NewsGuardian model API request failed: {tts_response.status.description}")
120
 
121
  elif model_type == "DALL-E":
122
  # Set up gRPC channel for DALL-E
 
154
  elif output_dalle.HasField("text"):
155
  st.text(output_dalle.text.raw)
156
 
157
+ elif model_type == "NewsGuardian model":
158
+ # Set up gRPC channel for NewsGuardian model
159
  channel_tts = ClarifaiChannel.get_grpc_channel()
160
  stub_tts = service_pb2_grpc.V2Stub(channel_tts)
161
  metadata_tts = (('authorization', 'Key ' + PAT_TTS),)
162
  userDataObject_tts = resources_pb2.UserAppIDSet(user_id=USER_ID_TTS, app_id=APP_ID_TTS)
163
 
164
+ # Prepare the request for NewsGuardian model
165
  input_data_tts = resources_pb2.Data()
166
 
167
  if raw_text:
 
177
  metadata=metadata_tts
178
  )
179
 
180
+ # Check if the request was successful for NewsGuardian model
181
  if post_model_outputs_response_tts.status.code != status_code_pb2.SUCCESS:
182
+ st.error(f"NewsGuardian model API request failed: {post_model_outputs_response_tts.status.description}")
183
  else:
184
+ # Get the output for NewsGuardian model
185
  output_tts = post_model_outputs_response_tts.outputs[0].data
186
 
187
+ # Display the result for NewsGuardian model
188
  if output_tts.HasField("text"):
189
  st.text(output_tts.text.raw)
190