Spaces:
Sleeping
Sleeping
File size: 10,390 Bytes
7e297e1 aa70e5c 7e297e1 aa70e5c 7e297e1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
import streamlit as st
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
# Set your Clarifai credentials and model details for GPT-4 Vision
PAT_GPT4 = '3ca5bd8b0f2244eb8d0e4b2838fc3cf1'
USER_ID_GPT4 = 'openai'
APP_ID_GPT4 = 'chat-completion'
MODEL_ID_GPT4 = 'openai-gpt-4-vision'
MODEL_VERSION_ID_GPT4 = '266df29bc09843e0aee9b7bf723c03c2'
# Set your Clarifai credentials and model details for DALL-E
PAT_DALLE = 'bfdeb4029ef54d23a2e608b0aa4c00e4'
USER_ID_DALLE = 'openai'
APP_ID_DALLE = 'dall-e'
MODEL_ID_DALLE = 'dall-e-3'
MODEL_VERSION_ID_DALLE = 'dc9dcb6ee67543cebc0b9a025861b868'
# Streamlit app
# Set your Clarifai credentials for Text-to-Speech (TTS)
PAT_TTS = 'bfdeb4029ef54d23a2e608b0aa4c00e4'
USER_ID_TTS = 'openai'
APP_ID_TTS = 'tts'
MODEL_ID_TTS = 'openai-tts-1'
MODEL_VERSION_ID_TTS = 'fff6ce1fd487457da95b79241ac6f02d'
# Set up gRPC channel for Text-to-Speech (TTS)
channel_tts = ClarifaiChannel.get_grpc_channel()
stub_tts = service_pb2_grpc.V2Stub(channel_tts)
metadata_tts = (('authorization', 'Key ' + PAT_TTS),)
userDataObject_tts = resources_pb2.UserAppIDSet(user_id=USER_ID_TTS, app_id=APP_ID_TTS,)
# Streamlit app
st.title("Fake news detection")
# Inserting logo
st.image("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTdA-MJ_SUCRgLs1prqudpMdaX4x-x10Zqlwp7cpzXWCMM9xjBAJYWdJsDlLoHBqNpj8qs&usqp=CAU")
# Function to get gRPC channel for Text-to-Speech (TTS)
def get_tts_channel():
channel_tts = ClarifaiChannel.get_grpc_channel()
return channel_tts, channel_tts.metadata
# User input
model_type = st.selectbox("Select Model", ["Fake news detection model"])
raw_text = st.text_area("This news is real or fake?")
image_upload = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
# Button to generate result
if st.button("Generate News Result"):
if model_type == "GPT-4 Vision":
# Set up gRPC channel for GPT-4 Vision
channel_gpt4 = ClarifaiChannel.get_grpc_channel()
stub_gpt4 = service_pb2_grpc.V2Stub(channel_gpt4)
metadata_gpt4 = (('authorization', 'Key ' + PAT_GPT4),)
userDataObject_gpt4 = resources_pb2.UserAppIDSet(user_id=USER_ID_GPT4, app_id=APP_ID_GPT4)
# Prepare the request for GPT-4 Vision
input_data_gpt4 = resources_pb2.Data()
if raw_text:
input_data_gpt4.text.raw = raw_text
if image_upload is not None:
image_bytes_gpt4 = image_upload.read()
input_data_gpt4.image.base64 = image_bytes_gpt4
post_model_outputs_response_gpt4 = stub_gpt4.PostModelOutputs(
service_pb2.PostModelOutputsRequest(
user_app_id=userDataObject_gpt4,
model_id=MODEL_ID_GPT4,
version_id=MODEL_VERSION_ID_GPT4,
inputs=[resources_pb2.Input(data=input_data_gpt4)]
),
metadata=metadata_gpt4 # Use metadata directly in the gRPC request
)
# Check if the request was successful for GPT-4 Vision
if post_model_outputs_response_gpt4.status.code != status_code_pb2.SUCCESS:
st.error(f"GPT-4 Vision API request failed: {post_model_outputs_response_gpt4.status.description}")
else:
# Get the output for GPT-4 Vision
output_gpt4 = post_model_outputs_response_gpt4.outputs[0].data
# Display the result for GPT-4 Vision
if output_gpt4.HasField("image"):
st.image(output_gpt4.image.base64, caption='Generated Image (GPT-4 Vision)', use_column_width=True)
elif output_gpt4.HasField("text"):
# Display the text result
st.text(output_gpt4.text.raw)
# Convert text to speech and play the audio
stub_tts = service_pb2_grpc.V2Stub(channel_gpt4) # Use the same channel for TTS
tts_input_data = resources_pb2.Data()
tts_input_data.text.raw = output_gpt4.text.raw
tts_response = stub_tts.PostModelOutputs(
service_pb2.PostModelOutputsRequest(
user_app_id=userDataObject_tts,
model_id=MODEL_ID_TTS,
version_id=MODEL_VERSION_ID_TTS,
inputs=[resources_pb2.Input(data=tts_input_data)]
),
metadata=metadata_gpt4 # Use the same metadata for TTS
)
# Check if the TTS request was successful
if tts_response.status.code == status_code_pb2.SUCCESS:
tts_output = tts_response.outputs[0].data
st.audio(tts_output.audio.base64, format='audio/wav')
else:
st.error(f"Text-to-Speech (TTS) API request failed: {tts_response.status.description}")
elif model_type == "DALL-E":
# Set up gRPC channel for DALL-E
channel_dalle = ClarifaiChannel.get_grpc_channel()
stub_dalle = service_pb2_grpc.V2Stub(channel_dalle)
metadata_dalle = (('authorization', 'Key ' + PAT_DALLE),)
userDataObject_dalle = resources_pb2.UserAppIDSet(user_id=USER_ID_DALLE, app_id=APP_ID_DALLE)
# Prepare the request for DALL-E
input_data_dalle = resources_pb2.Data()
if raw_text:
input_data_dalle.text.raw = raw_text
post_model_outputs_response_dalle = stub_dalle.PostModelOutputs(
service_pb2.PostModelOutputsRequest(
user_app_id=userDataObject_dalle,
model_id=MODEL_ID_DALLE,
version_id=MODEL_VERSION_ID_DALLE,
inputs=[resources_pb2.Input(data=input_data_dalle)]
),
metadata=metadata_dalle
)
# Check if the request was successful for DALL-E
if post_model_outputs_response_dalle.status.code != status_code_pb2.SUCCESS:
st.error(f"DALL-E API request failed: {post_model_outputs_response_dalle.status.description}")
else:
# Get the output for DALL-E
output_dalle = post_model_outputs_response_dalle.outputs[0].data
# Display the result for DALL-E
if output_dalle.HasField("image"):
st.image(output_dalle.image.base64, caption='Generated Image (DALL-E)', use_column_width=True)
elif output_dalle.HasField("text"):
st.text(output_dalle.text.raw)
elif model_type == "Text-to-Speech (TTS)":
# Set up gRPC channel for Text-to-Speech (TTS)
channel_tts = ClarifaiChannel.get_grpc_channel()
stub_tts = service_pb2_grpc.V2Stub(channel_tts)
metadata_tts = (('authorization', 'Key ' + PAT_TTS),)
userDataObject_tts = resources_pb2.UserAppIDSet(user_id=USER_ID_TTS, app_id=APP_ID_TTS)
# Prepare the request for Text-to-Speech (TTS)
input_data_tts = resources_pb2.Data()
if raw_text:
input_data_tts.text.raw = raw_text
post_model_outputs_response_tts = stub_tts.PostModelOutputs(
service_pb2.PostModelOutputsRequest(
user_app_id=userDataObject_tts,
model_id=MODEL_ID_TTS,
version_id=MODEL_VERSION_ID_TTS,
inputs=[resources_pb2.Input(data=input_data_tts)]
),
metadata=metadata_tts
)
# Check if the request was successful for Text-to-Speech (TTS)
if post_model_outputs_response_tts.status.code != status_code_pb2.SUCCESS:
st.error(f"Text-to-Speech (TTS) API request failed: {post_model_outputs_response_tts.status.description}")
else:
# Get the output for Text-to-Speech (TTS)
output_tts = post_model_outputs_response_tts.outputs[0].data
# Display the result for Text-to-Speech (TTS)
if output_tts.HasField("text"):
st.text(output_tts.text.raw)
if output_tts.HasField("audio"):
st.audio(output_tts.audio.base64, format='audio/wav')
# Add the beautiful social media icon section
st.markdown("""
<div align="center">
<a href="https://github.com/pyresearch/pyresearch" style="text-decoration:none;">
<img src="https://user-images.githubusercontent.com/34125851/226594737-c21e2dda-9cc6-42ef-b4e7-a685fea4a21d.png" width="2%" alt="" /></a>
<img src="https://user-images.githubusercontent.com/34125851/226595799-160b0da3-c9e0-4562-8544-5f20460f7cc9.png" width="2%" alt="" />
<a href="https://www.linkedin.com/company/pyresearch/" style="text-decoration:none;">
<img src="https://user-images.githubusercontent.com/34125851/226596446-746ffdd0-a47e-4452-84e3-bf11ec2aa26a.png" width="2%" alt="" /></a>
<img src="https://user-images.githubusercontent.com/34125851/226595799-160b0da3-c9e0-4562-8544-5f20460f7cc9.png" width="2%" alt="" />
<a href="https://twitter.com/Noorkhokhar10" style="text-decoration:none;">
<img src="https://user-images.githubusercontent.com/34125851/226599162-9b11194e-4998-440a-ba94-c8a5e1cdc676.png" width="2%" alt="" /></a>
<img src="https://user-images.githubusercontent.com/34125851/226595799-160b0da3-c9e0-4562-8544-5f20460f7cc9.png" width="2%" alt="" />
<a href="https://www.youtube.com/@Pyresearch" style="text-decoration:none;">
<img src="https://user-images.githubusercontent.com/34125851/226599904-7d5cc5c0-89d2-4d1e-891e-19bee1951744.png" width="2%" alt="" /></a>
<img src="https://user-images.githubusercontent.com/34125851/226595799-160b0da3-c9e0-4562-8544-5f20460f7cc9.png" width="2%" alt="" />
<a href="https://www.facebook.com/Pyresearch" style="text-decoration:none;">
<img src="https://user-images.githubusercontent.com/34125851/226600380-a87a9142-e8e0-4ec9-bf2c-dd6e9da2f05a.png" width="2%" alt="" /></a>
<img src="https://user-images.githubusercontent.com/34125851/226595799-160b0da3-c9e0-4562-8544-5f20460f7cc9.png" width="2%" alt="" />
<a href="https://www.instagram.com/pyresearch/" style="text-decoration:none;">
<img src="https://user-images.githubusercontent.com/34125851/226601355-ffe0b597-9840-4e10-bbef-43d6c74b5a9e.png" width="2%" alt="" /></a>
</div>
<hr>
""", unsafe_allow_html=True)
|