-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
689 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package data | ||
|
||
import com.travel.buddy.BuildKonfig | ||
import dev.shreyaspatil.ai.client.generativeai.GenerativeModel | ||
import dev.shreyaspatil.ai.client.generativeai.type.GenerateContentResponse | ||
import dev.shreyaspatil.ai.client.generativeai.type.PlatformImage | ||
import dev.shreyaspatil.ai.client.generativeai.type.content | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlin.io.encoding.ExperimentalEncodingApi | ||
|
||
class GeminiApi { | ||
companion object { | ||
const val PROMPT_GENERATE_UI = "Act as an Android app developer. " + | ||
"For the image provided, use Jetpack Compose to build the screen so that " + | ||
"the Compose Preview is as close to this image as possible. Also make sure " + | ||
"to include imports and use Material3. Only give code part without any extra " + | ||
"text or description neither at start or end, your response should contain " + | ||
"only code without any explanation." | ||
} | ||
|
||
|
||
private val apiKey = BuildKonfig.GEMINI_API_KEY | ||
|
||
|
||
val generativeVisionModel = GenerativeModel( | ||
modelName = "gemini-1.5-flash", | ||
apiKey = apiKey | ||
) | ||
|
||
val generativeModel = GenerativeModel( | ||
modelName = "gemini-pro", | ||
apiKey = apiKey | ||
) | ||
|
||
fun generateContent(prompt: String): Flow<GenerateContentResponse> { | ||
return generativeModel.generateContentStream(prompt) | ||
} | ||
|
||
@OptIn(ExperimentalEncodingApi::class) | ||
fun generateContent(prompt: String, imageData: ByteArray): Flow<GenerateContentResponse> { | ||
val content = content { | ||
image(PlatformImage(imageData)) | ||
text(prompt) | ||
} | ||
return generativeVisionModel.generateContentStream(content) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package model | ||
|
||
data class ChatMessage(val text: String, val isSender: Boolean) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package ui.component | ||
|
||
import androidx.compose.animation.core.FastOutSlowInEasing | ||
import androidx.compose.animation.core.RepeatMode | ||
import androidx.compose.animation.core.animateFloat | ||
import androidx.compose.animation.core.infiniteRepeatable | ||
import androidx.compose.animation.core.rememberInfiniteTransition | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.Brush | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import theme.PrimaryColor | ||
|
||
val ShimmerColorShades = listOf( | ||
Color.LightGray.copy(0.9f), | ||
PrimaryColor.copy(0.2f), | ||
Color.LightGray.copy(0.9f) | ||
) | ||
@Composable | ||
fun ShimmerAnimation( | ||
) { | ||
/* | ||
Create InfiniteTransition | ||
which holds child animation like [Transition] | ||
animations start running as soon as they enter | ||
the composition and do not stop unless they are removed | ||
*/ | ||
val transition = rememberInfiniteTransition() | ||
val translateAnim by transition.animateFloat( | ||
/* | ||
Specify animation positions, | ||
initial Values 0F means it | ||
starts from 0 position | ||
*/ | ||
initialValue = 0f, | ||
targetValue = 1000f, | ||
animationSpec = infiniteRepeatable( | ||
|
||
|
||
// Tween Animates between values over specified [durationMillis] | ||
tween(durationMillis = 1200, easing = FastOutSlowInEasing), | ||
RepeatMode.Reverse | ||
) | ||
) | ||
|
||
/* | ||
Create a gradient using the list of colors | ||
Use Linear Gradient for animating in any direction according to requirement | ||
start=specifies the position to start with in cartesian like system Offset(10f,10f) means x(10,0) , y(0,10) | ||
end = Animate the end position to give the shimmer effect using the transition created above | ||
*/ | ||
val brush = Brush.linearGradient( | ||
colors = ShimmerColorShades, | ||
start = Offset(10f, 10f), | ||
end = Offset(translateAnim, translateAnim) | ||
) | ||
|
||
ShimmerItem(brush = brush) | ||
} | ||
|
||
@Composable | ||
fun ShimmerItem( | ||
brush: Brush | ||
) { | ||
Spacer( | ||
modifier = Modifier | ||
.padding(top = 8.dp) | ||
.fillMaxWidth() | ||
.size(20.dp) | ||
.background(brush = brush, shape = RoundedCornerShape(8.dp)) | ||
) | ||
} |
Oops, something went wrong.