File size: 1,832 Bytes
1763118
 
 
 
 
 
 
 
 
222a957
1763118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
"""Untitled25.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1i4BW958q6NUrUaJ2bAgNM8-N1pLSeP-Q
"""

#pip install openai streamlit



import openai
import streamlit as st

# Initialize OpenAI API and server base
openai.api_key = "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"
openai.api_base = "http://zanino.millennium.berkeley.edu:8000/v1"

# Set Streamlit layout
st.set_page_config(layout="wide")

# Function to get response from Gorilla Server
def get_gorilla_response(prompt, model):
    try:
        completion = openai.ChatCompletion.create(
            model=model,
            messages=[{"role": "user", "content": prompt}]
        )
        return completion.choices[0].message.content
    except Exception as e:
        print("An error occurred:", e)

def main():
    st.title("Gorilla LLM")
    input_prompt = st.text_area("Enter your prompt:")

    model_options = ('gorilla-7b-hf-v1', 'gorilla-mpt-7b-hf-v0')
    option = st.selectbox('Select a model:', model_options)

    if st.button("Create"):
        if len(input_prompt) > 0:
            result = get_gorilla_response(prompt=input_prompt, model=option)
            st.write(result)
            # ...

if st.button("Gorilla Magic"):
    if len(input_prompt) > 0:
        # ...
        with col2:
            code_result = extract_code_from_output(result)
            if option == "gorilla-7b-hf-v1":
                st.subheader("Generated Output")
                st.code(code_result, language='python')
            elif option == "gorilla-mpt-7b-hf-v0":
                lines = code_result.split('\\n')
                for line in lines[:-1]:
                    st.code(line, language='python')
            # ...
            run_generated_code(file_path)