sccastillo commited on
Commit
1a3d12e
·
1 Parent(s): 47b9c12

app en gradio

Browse files
Files changed (4) hide show
  1. .env +2 -0
  2. .gitignore +2 -0
  3. app.py +19 -9
  4. requirements.txt +4 -1
.env ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ GEAI_API_KEY = "default_PMzB2IbcL3OWamWX0XYsUtR8SCOcLFPZ3cAmokIbchcYwK6KbQBtX1eJ5BLrCfsFqxRnJ0CgyM2yiLVnPzHh9Q"
2
+ GEAI_API_BASE_URL = "https://api.saia.ai/chat"
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .gradiotest
2
+ .gradiotest/lib/python3.12/site-packages/aiofiles/base.py
app.py CHANGED
@@ -1,10 +1,19 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
 
 
 
 
 
3
 
4
  """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
  """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
 
 
 
8
 
9
 
10
  def respond(
@@ -27,17 +36,18 @@ def respond(
27
 
28
  response = ""
29
 
30
- for message in client.chat_completion(
31
- messages,
 
32
  max_tokens=max_tokens,
33
  stream=True,
34
  temperature=temperature,
35
  top_p=top_p,
36
  ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
41
 
42
 
43
  """
 
1
  import gradio as gr
2
+ from openai import OpenAI
3
+ import os
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables from .env file
7
+ load_dotenv()
8
 
9
  """
10
+ OpenAI Chat Completion API integration
11
  """
12
+
13
+ GEAI_API_KEY = os.getenv("GEAI_API_KEY")
14
+ GEAI_API_BASE_URL = os.getenv("GEAI_API_BASE_URL")
15
+
16
+ client = OpenAI(api_key=GEAI_API_KEY, base_url=GEAI_API_BASE_URL)
17
 
18
 
19
  def respond(
 
36
 
37
  response = ""
38
 
39
+ for chunk in client.chat.completions.create(
40
+ model="openai/gpt-4o-mini",
41
+ messages=messages,
42
  max_tokens=max_tokens,
43
  stream=True,
44
  temperature=temperature,
45
  top_p=top_p,
46
  ):
47
+ if chunk.choices[0].delta.content is not None:
48
+ token = chunk.choices[0].delta.content
49
+ response += token
50
+ yield response
51
 
52
 
53
  """
requirements.txt CHANGED
@@ -1 +1,4 @@
1
- huggingface_hub==0.25.2
 
 
 
 
1
+ huggingface_hub==0.25.2
2
+ openai
3
+ python-dotenv
4
+ gradio