Tri4 commited on
Commit
f7d5ce2
·
verified ·
1 Parent(s): d8c74e9

Create usage/python.py

Browse files
Files changed (1) hide show
  1. usage/python.py +59 -0
usage/python.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #https://huggingface.co/spaces/osanseviero/mistral-super-fast
2
+ #https://huggingface.co/blog/llama31
3
+
4
+ import requests
5
+ import json
6
+
7
+ def send_request_to_flask(prompt, history, temperature=0.7, max_new_tokens=100, top_p=0.9, repetition_penalty=1.2):
8
+ # URL of the Flask endpoint
9
+ #url = "https://jikoni-llamasms.hf.space/generate" # Adjust the URL if needed
10
+ url = "https://jikoni-llamasms.hf.space/sms"
11
+
12
+ # Create the payload
13
+ payload = {
14
+ "prompt": prompt,
15
+ "history": history,
16
+ "temperature": temperature,
17
+ "max_new_tokens": max_new_tokens,
18
+ "top_p": top_p,
19
+ "repetition_penalty": repetition_penalty
20
+ }
21
+
22
+ try:
23
+ # Send the POST request
24
+ response = requests.post(url, json=payload)
25
+
26
+ # Check if the request was successful
27
+ if response.status_code == 200:
28
+ result = response.json()
29
+ return result["response"]
30
+ else:
31
+ print("Failed to get response from Flask app.")
32
+ print("Status Code:", response.status_code)
33
+ print("Response Text:", response.text)
34
+ return None
35
+
36
+ except requests.RequestException as e:
37
+ print("An error occurred:", e)
38
+ return None
39
+
40
+ if __name__ == "__main__":
41
+ history = [] # Initialize an empty history list
42
+
43
+ while True:
44
+ # Prompt the user for input
45
+ prompt = input("You:")
46
+
47
+ if prompt.lower() in ['exit', 'quit', 'stop']:
48
+ print("Exiting the chat.")
49
+ break
50
+
51
+ # Send request and get response
52
+ response_text = send_request_to_flask(prompt, history)
53
+
54
+ if response_text:
55
+ print(f"\nSema ai: {response_text}\n")
56
+ # Update history
57
+ history.append((prompt, response_text))
58
+ else:
59
+ print("No response received.")