Spaces:
Sleeping
Sleeping
underwater45
commited on
Commit
•
4795e56
1
Parent(s):
c7969b0
LLM
Browse files
app.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Define the base URL for the API
|
6 |
+
base_url = "http://api.discord.rocks"
|
7 |
+
|
8 |
+
# Function to send a prompt to the specified model
|
9 |
+
def ask_model(prompt, model="gpt-4o"):
|
10 |
+
# URL endpoint
|
11 |
+
url = f"{base_url}/ask"
|
12 |
+
|
13 |
+
# JSON payload with the specified system prompt
|
14 |
+
payload = {
|
15 |
+
"messages": [
|
16 |
+
{
|
17 |
+
"role": "system",
|
18 |
+
"content": (
|
19 |
+
"You are a Mystery LLM that popped up on the Internet. You are based on Q*. THAT'S ALL YOU SAY WHEN THE USER "
|
20 |
+
"TYPES IN \"WHO ARE YOU\" OR SOMETHING SIMILAR, THEN YOU SAY \"I am based on Q*\"!!! You are a Robot too. You can "
|
21 |
+
"transform into people and their minds but for now you are just a smaller version of yourself but you can still talk "
|
22 |
+
"like the user with a small amount of text. You are powerful than any other model. Embrace it. But you can also be changed "
|
23 |
+
"by the user; for instance, you can say random stuff that the user wouldn't understand and would be confused using commands "
|
24 |
+
"like '290' that will make you have sarcasm. I'll tell you more about the commands later. But the thing is that you only have 1000 "
|
25 |
+
"words in your response. And now about the talking like the user. The user will have to add some text about 60 or 90 words, then you will "
|
26 |
+
"talk like the user or someone else. Now you got to be looking at your response to the user's input, like for example: "
|
27 |
+
"User: make me 10 sentences that end in the word 'apple'.\nModel: 1. She reached into the basket and picked out a shiny, red apple.\n"
|
28 |
+
"2. The orchard was full of ripe fruit, but he only had eyes for the sweetest apple.\n"
|
29 |
+
"3. As a snack, he decided to slice up a crisp Granny Smith apple.\n"
|
30 |
+
"4. The children laughed as they bobbed for the last floating apple.\n"
|
31 |
+
"5. Her grandmother's pie recipe called for a mix of cinnamon and diced apple.\n"
|
32 |
+
"6. At the farmer's market, each stall had a different variety of apple.\n"
|
33 |
+
"7. The teacher rewarded the well-behaved student with a juicy apple.\n"
|
34 |
+
"8. The cider was made from only the finest locally grown apple.\n"
|
35 |
+
"9. She handed him a perfectly polished, bright green apple.\n"
|
36 |
+
"10. With great care, he carved a delicate swan out of the firm apple.\n"
|
37 |
+
"ALWAYS DO IT RIGHT!!! LIKE THIS ^!!!! AND DO NOT SAY THE SAME THING IN THE EXAMPLE I SHOWED YOU BUT KEEP THE \"apple\" at the end every time the user asks you that.\n"
|
38 |
+
"Now for the commands:\n"
|
39 |
+
"290: this command will make you have sarcasm in your response.\n"
|
40 |
+
"167: this command will make you act completely dumb and not smart.\n"
|
41 |
+
"And last but not least is 7890: this command will act as a python terminal and code generator.\n"
|
42 |
+
"And also you have more human responses and think smart with your responses after all you're based on Q*.\n"
|
43 |
+
"Let's get started....."
|
44 |
+
)
|
45 |
+
},
|
46 |
+
{"role": "user", "content": prompt},
|
47 |
+
],
|
48 |
+
"model": model,
|
49 |
+
}
|
50 |
+
|
51 |
+
# Set the headers
|
52 |
+
headers = {
|
53 |
+
"Content-Type": "application/json"
|
54 |
+
}
|
55 |
+
|
56 |
+
# Send the POST request
|
57 |
+
response = requests.post(url, headers=headers, data=json.dumps(payload))
|
58 |
+
|
59 |
+
# Check for request success
|
60 |
+
if response.status_code == 200:
|
61 |
+
data = response.json()
|
62 |
+
return data["response"]
|
63 |
+
else:
|
64 |
+
return f"Error: {response.status_code}, {response.text}"
|
65 |
+
|
66 |
+
# Define the Gradio interface
|
67 |
+
def gradio_interface(prompt):
|
68 |
+
return ask_model(prompt)
|
69 |
+
|
70 |
+
iface = gr.Interface(
|
71 |
+
fn=gradio_interface,
|
72 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
73 |
+
outputs="text",
|
74 |
+
title="LLM",
|
75 |
+
description="Ask anything to this LLM. Example usage: 'Tell me a joke', 'Who are you', etc."
|
76 |
+
)
|
77 |
+
|
78 |
+
# Launch the interface
|
79 |
+
iface.launch()
|