Spaces:
Sleeping
Sleeping
File size: 1,824 Bytes
f7d5ce2 |
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 |
#https://huggingface.co/spaces/osanseviero/mistral-super-fast
#https://huggingface.co/blog/llama31
import requests
import json
def send_request_to_flask(prompt, history, temperature=0.7, max_new_tokens=100, top_p=0.9, repetition_penalty=1.2):
# URL of the Flask endpoint
#url = "https://jikoni-llamasms.hf.space/generate" # Adjust the URL if needed
url = "https://jikoni-llamasms.hf.space/sms"
# Create the payload
payload = {
"prompt": prompt,
"history": history,
"temperature": temperature,
"max_new_tokens": max_new_tokens,
"top_p": top_p,
"repetition_penalty": repetition_penalty
}
try:
# Send the POST request
response = requests.post(url, json=payload)
# Check if the request was successful
if response.status_code == 200:
result = response.json()
return result["response"]
else:
print("Failed to get response from Flask app.")
print("Status Code:", response.status_code)
print("Response Text:", response.text)
return None
except requests.RequestException as e:
print("An error occurred:", e)
return None
if __name__ == "__main__":
history = [] # Initialize an empty history list
while True:
# Prompt the user for input
prompt = input("You:")
if prompt.lower() in ['exit', 'quit', 'stop']:
print("Exiting the chat.")
break
# Send request and get response
response_text = send_request_to_flask(prompt, history)
if response_text:
print(f"\nSema ai: {response_text}\n")
# Update history
history.append((prompt, response_text))
else:
print("No response received.")
|