hertogateis commited on
Commit
b0d08f5
·
verified ·
1 Parent(s): cc86e76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -23
app.py CHANGED
@@ -1,27 +1,36 @@
1
- import streamlit as st
2
- import transformers
3
- from transformers import GPT2LMHeadModel, GPT2Tokenizer
4
 
5
- #from transformers import T5Tokenizer, T5ForConditionalGeneration
6
- #model_name = "t5-base"
7
- #tokenizer = T5Tokenizer.from_pretrained(model_name)
8
- #model = T5ForConditionalGeneration.from_pretrained(model_name)
9
- model_name = "indonesia/gpt-2-small-indonesia"
10
- model = GPT2LMHeadModel.from_pretrained(model_name)
11
- tokenizer = GPT2Tokenizer.from_pretrained(model_name)
12
 
13
- def generate_response(input_text):
14
- input_ids = tokenizer.encode(input_text, return_tensors='pt')
15
- outputs = model.generate(input_ids,
16
- min_length=5,
17
- max_length=300,
18
- do_sample=True, num_beams=5, no_repeat_ngram_size=2)
19
- generated_text = tokenizer.decode(
20
- outputs[0], skip_special_tokens=True)
21
- return generated_text
22
 
 
 
 
 
 
 
 
 
 
23
 
24
- prompt = st.chat_input(placeholder="Say Something!",key=None, max_chars=None, disabled=False, on_submit=None, args=None, kwargs=None)
25
- if prompt:
26
- with st.chat_message(name="AI",avatar=None):
27
- st.write(generate_response(prompt))
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
 
3
 
4
+ # Replace with your actual API key
5
+ API_KEY = "sk-3df8d86d5a4b49cb9240077792c55d0a"
6
+ API_URL = "https://api.deepseek.com/v1/chat/completions" # Example endpoint, check documentation
 
 
 
 
7
 
8
+ # Define the prompt in Bahasa Indonesia
9
+ prompt = "Halo, bisakah kamu membantu saya membuat rencana perjalanan ke Bali?"
 
 
 
 
 
 
 
10
 
11
+ # Prepare the payload
12
+ payload = {
13
+ "model": "deepseek-v3", # Replace with the model you want to use
14
+ "messages": [
15
+ {"role": "user", "content": prompt}
16
+ ],
17
+ "max_tokens": 150, # Adjust as needed
18
+ "temperature": 0.7, # Adjust for creativity
19
+ }
20
 
21
+ # Set headers
22
+ headers = {
23
+ "Authorization": f"Bearer {API_KEY}",
24
+ "Content-Type": "application/json",
25
+ }
26
+
27
+ # Make the API request
28
+ response = requests.post(API_URL, headers=headers, data=json.dumps(payload))
29
+
30
+ # Check the response
31
+ if response.status_code == 200:
32
+ result = response.json()
33
+ generated_text = result['choices'][0]['message']['content']
34
+ print("Generated Text:", generated_text)
35
+ else:
36
+ print("Error:", response.status_code, response.text)