loztcontrol commited on
Commit
c4e6c36
1 Parent(s): 0311faf

Upload 3 files

Browse files

#first version. Be patient

Files changed (3) hide show
  1. README.md +15 -5
  2. app.py +63 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,23 @@
1
  ---
2
- title: Messmerbox
3
- emoji: 👁
4
- colorFrom: purple
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 4.44.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
 
 
 
 
 
 
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: Chat-with-OpenAI-o1
3
+ emoji: 🚀
4
+ colorFrom: red
5
+ colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 4.44.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
+ duplicated_from: ysharma/ChatGPT4
12
+ disable_embedding: true
13
+ datasets:
14
+ - allenai/WildChat-1M
15
+ - allenai/WildChat-1M-Full
16
+ - allenai/WildChat
17
+ models:
18
+ - allenai/WildLlama-7b-user-assistant
19
+ - allenai/WildLlama-7b-assistant-only
20
  ---
21
 
22
+ - https://arxiv.org/abs/2405.01470
23
+ - https://arxiv.org/abs/2409.03753
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import requests
4
+ import random
5
+
6
+ # Variables de entorno necesarias
7
+ API_URL = os.getenv("API_URL")
8
+ OPENAI_API_KEYS = os.getenv("OPENAI_API_KEYS", "").split(',')
9
+ NUM_THREADS = int(os.getenv("NUM_THREADS", "1"))
10
+
11
+ # Verifica que las variables de entorno necesarias estén definidas
12
+ if not API_URL or not OPENAI_API_KEYS:
13
+ raise ValueError("API_URL y OPENAI_API_KEYS deben estar definidas en el entorno.")
14
+
15
+ # Función para manejar errores
16
+ def exception_handler(exception_type, exception, traceback):
17
+ print(f"{exception_type.__name__}: {exception}")
18
+ sys.excepthook = exception_handler
19
+ sys.tracebacklimit = 0
20
+
21
+ # Función que procesa bloques de código en Markdown para ser renderizado en HTML
22
+ def parse_codeblock(text):
23
+ lines = text.split("\n")
24
+ for i, line in enumerate(lines):
25
+ if "```" in line:
26
+ if line != "```":
27
+ lines[i] = f'<pre><code class="{lines[i][3:]}">'
28
+ else:
29
+ lines[i] = '</code></pre>'
30
+ else:
31
+ if i > 0:
32
+ lines[i] = "<br/>" + line.replace("<", "&lt;").replace(">", "&gt;")
33
+ return "\n".join(lines)
34
+
35
+ # Función principal que interactúa con el modelo o API externa
36
+ def query_api(input_text):
37
+ headers = {"Authorization": f"Bearer {random.choice(OPENAI_API_KEYS)}"}
38
+ payload = {"input": input_text}
39
+
40
+ try:
41
+ response = requests.post(API_URL, json=payload, headers=headers)
42
+ if response.status_code == 200:
43
+ return response.json().get("output", "No response from API.")
44
+ else:
45
+ return f"Error: {response.status_code} - {response.text}"
46
+ except Exception as e:
47
+ return f"Excepción en la consulta: {str(e)}"
48
+
49
+ # Interfaz de Gradio
50
+ def app_function(input_text):
51
+ # Llamada a la función que consulta la API
52
+ result = query_api(input_text)
53
+ return result
54
+
55
+ # Definir la interfaz de Gradio
56
+ interface = gr.Interface(fn=app_function, inputs="text", outputs="text",
57
+ title="Consulta a la API",
58
+ description="Introduce un texto para consultar la API.")
59
+
60
+ # Ejecutar la interfaz en Hugging Face
61
+ if __name__ == "__main__":
62
+ interface.launch()
63
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ requests
3
+