Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from openai import OpenAI | |
| BASE_URL = "https://w0xtwbf2fdxe1q-8000.proxy.runpod.net/v1/chat/completions" | |
| API_KEY="SOMEHOW" | |
| # Create an OpenAI client to interact with the API server | |
| client = OpenAI( | |
| base_url=BASE_URL, | |
| api_key=API_KEY | |
| ) | |
| def predict(message, history): | |
| # Convert chat history to OpenAI format | |
| history_openai_format = [{ | |
| "role": "system", | |
| "content": "Tu es un excellent assistant IA développé par WAY2CALL pour faire des évaluations en JSON des audios transcrits." | |
| }] | |
| for i, (human, assistant) in enumerate(history): | |
| if i % 2 == 0: | |
| history_openai_format.append({"role": "user", "content": human}) | |
| else: | |
| history_openai_format.append({"role": "assistant", "content": assistant}) | |
| history_openai_format.append({"role": "user", "content": message}) | |
| # Create a chat completion request and send it to the API server | |
| stream = client.chat.completions.create( | |
| model="way2call/way2call-7b-evaluation-instruct", # Model name to use | |
| messages=history_openai_format, # Chat history | |
| temperature=0.1, # Temperature for text generation | |
| stream=True, # Stream response | |
| ) | |
| # Read and return generated text from response stream | |
| partial_message = "" | |
| for chunk in stream: | |
| partial_message += (chunk.choices[0].delta.content or "") | |
| yield partial_message | |
| # Create and launch a chat interface with Gradio | |
| gr.ChatInterface(predict).queue().launch() |