Spaces:
Sleeping
Sleeping
| # import gradio as gr | |
| # # ๊ฐ๋จํ ์ธ์ฌ ํจ์ | |
| # def greet(name): | |
| # return f"Hello {name}!" | |
| # # Gradio ์ธํฐํ์ด์ค ์ ์ | |
| # demo = gr.Interface(fn=greet, inputs="text", outputs="text") | |
| # demo.launch() | |
| import gradio as gr | |
| import requests | |
| # Azure OpenAI API ํธ์ถ ํจ์ | |
| def ask_gpt(user_text): | |
| endpoint = "https://5b040-openai.openai.azure.com/openai/deployments/gpt-4o-mini/chat/completions?api-version=2024-02-15-preview" | |
| api_key = "6tuIuMEHIu3wJHSnkBCXFqaNnKcmraKNgm6mS585Q6auFzJBvLfAJQQJ99AKACfhMk5XJ3w3AAABACOGO5fD" | |
| headers = { | |
| "Content-Type": "application/json", | |
| "api-key": api_key | |
| } | |
| payload = { | |
| "messages": [ | |
| {"role": "system", "content": "You are a helpful assistant."}, | |
| {"role": "user", "content": user_text} | |
| ], | |
| "temperature": 0.7, | |
| "max_tokens": 800 | |
| } | |
| response = requests.post(endpoint, headers=headers, json=payload) | |
| if response.status_code == 200: | |
| return response.json()["choices"][0]["message"]["content"] | |
| else: | |
| return f"Error: {response.status_code}, {response.text}" | |
| # Gradio ์ธํฐํ์ด์ค | |
| interface = gr.Interface( | |
| fn=ask_gpt, | |
| inputs="text", | |
| outputs="text", | |
| title="Azure OpenAI Chat", | |
| description="Azure OpenAI API๋ฅผ ํตํด GPT ๋ชจ๋ธ๊ณผ ์ํธ์์ฉํ ์ ์๋ ์ธํฐํ์ด์ค์ ๋๋ค." | |
| ) | |
| # ์คํ | |
| interface.launch() | |