Spaces:
Sleeping
Sleeping
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() |