Team Ai
Apppublic

Tonic/open-gpt-Python-Coding-Assistant

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
app.py62 linesDownload Raw Back to root
1 2SYSTEM_PROMPT = "As an LLM, my job is to help users with their Python coding. I should provide clear and concise prompts that help users write clean, efficient, and accurate Python code."3TITLE = "Python Coding Assistant"4EXAMPLE_INPUT = "[ADD CODE HERE] Improve the efficiency of the loop above"5import gradio as gr6from gradio_client import Client7import os8import requests9 10tulu = "https://tonic1-tulu.hf.space/--replicas/vhgch/"11 12def predict_beta(message, chatbot=[], system_prompt=""):13    client = Client(tulu)14 15    try:16        max_new_tokens = 35017        temperature = 0.418        top_p = 0.919        repetition_penalty = 0.920        advanced = False21 22        # Making the prediction23        result = client.predict(24            message,25            system_prompt,26            max_new_tokens,27            temperature,28            top_p,29            repetition_penalty,30            advanced,31            fn_index=032        )33        print("Raw API Response:", result)  # Debugging print34        if result is not None:35            print("Processed bot_message:", result)  # Debugging print36            return result37        else:38            print("No response or empty response from the model.")  # Debugging print39            return None40            41    except Exception as e:42        error_msg = f"An error occurred: {str(e)}"43        print(error_msg)  # Debugging print44        return None45 46def test_preview_chatbot(message, history):47    response = predict_beta(message, history, SYSTEM_PROMPT)48    return response49 50 51welcome_preview_message = f"""52Welcome to **{TITLE}** using [Allen AI/Tulu](https://huggingface.co/allenai/tulu-2-dpo-13b) ! Say something like: 53 54''{EXAMPLE_INPUT}''55"""56 57chatbot_preview = gr.Chatbot(layout="panel", value=[(None, welcome_preview_message)])58textbox_preview = gr.Textbox(scale=7, container=False, value=EXAMPLE_INPUT)59 60demo = gr.ChatInterface(test_preview_chatbot, chatbot=chatbot_preview, textbox=textbox_preview)61 62demo.launch()