import gradio as gr import openai from openai import OpenAI import os api_secret = os.getenv('openaikey') model = os.getenv('model') client = OpenAI(api_key=api_secret) sysint ='Sampean asisten ingkang mangsuli ngangge basa Jawa Krama, sanes Ngoko.' def ask(request, temp, topp,): chat_completion = client.chat.completions.create( messages=[ {"role": 'system', "content": sysint}, {"role": 'user', "content": request}], temperature=temp, top_p=topp, max_tokens=700, model=model ) response = chat_completion.choices[0].message.content return response with gr.Blocks(theme='snehilsanyal/scikit-learn') as app: gr.Interface( fn=ask, inputs=[ gr.Textbox(value='Panjenengan saged nerangaken menapa kacerdhasan gaweyan saged gadhah peranan wigatos babagan pelestarian basa?', label="Pitakenan Jawa Krama"), gr.Slider(label="Temperature",minimum=0,maximum=1,value=.5,step=.05), gr.Slider(label="Top p",minimum=0,maximum=1,value=.5,step=.05) ], outputs=gr.Textbox(label="Mangsulan"), title="Jawa Krama Chatbot Demo", allow_flagging="never", description='This is a fine-tuned version of GPT-3.5 Turbo, trained to speak Krama Javanese. The model is optimized to respond to educational questions.') app.launch(debug=True, share=True)