Spaces:
Sleeping
Sleeping
File size: 3,968 Bytes
5774a62 bd8a26c b8ecd36 1f3531d bd8a26c 49162c6 1f3531d 49162c6 1f3531d 49162c6 bd8a26c 49162c6 bd8a26c da5c532 bd8a26c da5c532 1f3531d da5c532 bd8a26c da5c532 bd8a26c da5c532 bd8a26c da5c532 bd8a26c 1f3531d bd8a26c da5c532 bd8a26c 1f3531d bd8a26c da5c532 bd8a26c 49162c6 bd8a26c 49162c6 |
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 |
import gradio as gr
import requests
import openai
from deep_translator import GoogleTranslator
import os
openkey = os.getenv("openkey")
yelpkey = os.getenv("yelpkey")
def generate_text(text):
url = f"https://api.yelp.com/v3/businesses/{text}/reviews?limit=1&sort_by=yelp_sort"
headers = {
"accept": "application/json",
"Authorization": yelpkey
}
response = requests.get(url, headers=headers)
response = response.json()
review = response['reviews'][0]['text']
user = response['reviews'][0]['user']['name']
image = response['reviews'][0]['user']['image_url']
link = response['reviews'][0]['url']
calificacion = response['reviews'][0]['rating']
creacion = response['reviews'][0]['time_created']
openai.api_key = openkey
traductor = GoogleTranslator(source='en', target='es')
traduccion = traductor.translate(review)
response2 = openai.Completion.create(
model="text-davinci-003",
prompt= f"Responder la siguiente reseña. nombre:{user}. {review}",
temperature=0.5,
max_tokens=300,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
response2 = response2.choices[0].text
return review,user,image,response2,traduccion,calificacion,creacion
with gr.Blocks() as demo:
gr.Markdown(
"""
<p align="center">
<img width = 600 src="https://neurona-ba.com/wp-content/uploads/2021/07/HenryLogo.jpg">
<img width = 450 src="https://raw.githubusercontent.com/BonfantiMatias/images/main/proyecto.jpg">
<img width = 400 src="https://raw.githubusercontent.com/BonfantiMatias/images/main/proyecto2.jpg">
</p>
<p align="center">
<img width=1024 src="https://raw.githubusercontent.com/BonfantiMatias/images/main/COMOFUNCIONA.png">
</p>
"""
)
gr.Markdown(
"""
<p align="center">
</p>
<p align="center">
</p>
"""
)
gr.Markdown("# Ingresar el Negocio")
gr.Markdown(
"""
- Puede ingresar el Negocio por su ID o Alias de [YELP.com](https://www.yelp.com)
- Presionar el Boton 'Iniciar Modelo' que se encuentra al final de la pagina
"""
)
with gr.Column():
seed = gr.Textbox(label="Introducir el nombre de la empresa o su Id")
with gr.Row():
gr.Examples(["la-fábrica-del-taco-buenos-aires"], inputs=[seed])
gr.Examples(["versailles-miami-4"], inputs=[seed])
gr.Examples(["la-casa-de-toño-ciudad-de-méxico-4"], inputs=[seed])
gr.Examples(["osteria-del-bugiardo-verona"], inputs=[seed])
gr.Examples(["arume-barcelona"], inputs=[seed])
gr.Markdown("# Mediante la Api Yelp Fusion se obtienen los datos de la ultima reseña del local seleccionado")
with gr.Row():
with gr.Column():
user = gr.Textbox(label="Id Cliente" )
review = gr.Textbox(label="Reseña Cliente")
calificacion = gr.Textbox(label="Calificacion de la reseña")
creacion = gr.Textbox(label="Fecha de creacion de la reseña")
with gr.Column():
image = gr.Image(label="Avatar Cliente")
gr.Markdown("# Traduccion de la reseña al idioma español")
with gr.Row():
traduccion = gr.Textbox(label="Traduccion reseña")
gr.Markdown("# Respuesta de la reseña implementando el modelo GPT-3 de OpenAi")
with gr.Row():
response2 = gr.Textbox(label="Respuesta GPT-3")
with gr.Row():
btn = gr.Button("Iniciar Modelo")
btn.click(generate_text, inputs=[seed], outputs=[review,user,image,response2,traduccion,calificacion,creacion])
if __name__ == "__main__":
demo.launch() |