Spaces:
Runtime error
Runtime error
Federico69
commited on
Commit
•
dec807c
1
Parent(s):
b4bff45
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: pink
|
5 |
-
colorTo: blue
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.28.3
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: chatfp
|
3 |
+
app_file: chatfp.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
sdk_version: 4.28.3
|
|
|
|
|
6 |
---
|
|
|
|
chatfp.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import os # Importa os para acceder a variables de entorno
|
4 |
+
|
5 |
+
# Define la función que interactúa con ChatGPT-4
|
6 |
+
def chat_with_gpt4(prompt):
|
7 |
+
api_key = os.getenv("OPENAI_API_KEY") # Obtén la clave API desde los secretos configurados
|
8 |
+
if not api_key:
|
9 |
+
raise ValueError("API key not found. Please set up the OPENAI_API_KEY environment variable.")
|
10 |
+
|
11 |
+
headers = {
|
12 |
+
'Authorization': f'Bearer {api_key}',
|
13 |
+
'Content-Type': 'application/json',
|
14 |
+
}
|
15 |
+
data = {
|
16 |
+
'model': 'gpt-4', # Asegúrate de utilizar el modelo correcto de GPT
|
17 |
+
'prompt': prompt,
|
18 |
+
'max_tokens': 150 # Puedes ajustar el número de tokens según necesites
|
19 |
+
}
|
20 |
+
response = requests.post('https://api.openai.com/v1/chat/completions', headers=headers, json=data)
|
21 |
+
if response.status_code == 200:
|
22 |
+
return response.json()['choices'][0]['message']['content']
|
23 |
+
else:
|
24 |
+
return "Error en la API de OpenAI: " + response.text
|
25 |
+
|
26 |
+
# Crea la interfaz de Gradio
|
27 |
+
interface = gr.Interface(
|
28 |
+
fn=chat_with_gpt4,
|
29 |
+
inputs=gr.Textbox(lines=2, placeholder="Escribe aquí tu pregunta para GPT-4..."),
|
30 |
+
outputs='text',
|
31 |
+
title="Chatbot con ChatGPT-4",
|
32 |
+
description="Este chatbot utiliza ChatGPT-4 para responder a tus preguntas. ¡Pruébalo!"
|
33 |
+
)
|
34 |
+
|
35 |
+
if __name__ == "__main__":
|
36 |
+
interface.launch()
|